Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added feature connect to ssh on alternate ports #6

Open
wants to merge 1 commit into from

5 participants

IT House Matt Bailey Cássio Oseki Sergey Smagin Valdis Pornieks
IT House

Hello Adam,
I had to access some servers where sshd is configured to listen to other ports than 22
With this commit you can do
remote = Rush::Box.new("example.com:2222")
2 tests added, no tests broken

Matt Bailey

+1 on this pull request, would really like this feature.

Cássio Oseki

Sorry for ressurecting 2 years old issue but, isn't editing ~/.ssh/config better?

Host example
    HostName example.com
    Port 2222
Sergey Smagin

@empjustine sure it is (I'm sorry too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 30, 2010
  1. Valdis Pornieks
This page is out of date. Refresh to see the latest.
1  lib/rush/config.rb
View
@@ -1,6 +1,7 @@
# The config class accesses files in ~/.rush to load and save user preferences.
class Rush::Config
DefaultPort = 7770
+ DefaultSshPort = 22
attr_reader :dir
11 lib/rush/ssh_tunnel.rb
View
@@ -2,7 +2,8 @@
# HTTP commands can be sent by Rush::Connection::Remote.
class Rush::SshTunnel
def initialize(real_host)
- @real_host = real_host
+ @real_host, @real_port = real_host.split(':',2)
+ @real_port = @real_port || Rush::Config::DefaultSshPort
end
def host
@@ -13,6 +14,10 @@ def port
@port
end
+ def real_port
+ @real_port
+ end
+
def ensure_tunnel(options={})
return if @port and tunnel_alive?
@@ -81,7 +86,7 @@ class SshFailed < Exception; end
class NoPortSelectedYet < Exception; end
def ssh(command)
- raise SshFailed unless system("ssh #{@real_host} '#{command}'")
+ raise SshFailed unless system("ssh -p #{real_port} #{@real_host} '#{command}'")
end
def make_ssh_tunnel(options={})
@@ -91,7 +96,7 @@ def make_ssh_tunnel(options={})
def ssh_tunnel_command_without_stall
options = tunnel_options
raise NoPortSelectedYet unless options[:local_port]
- "ssh -f -L #{options[:local_port]}:127.0.0.1:#{options[:remote_port]} #{options[:ssh_host]}"
+ "ssh -p #{real_port} -f -L #{options[:local_port]}:127.0.0.1:#{options[:remote_port]} #{options[:ssh_host]}"
end
def ssh_stall_command(options={})
27 spec/ssh_tunnel_spec.rb
View
@@ -80,7 +80,7 @@
:remote_port => 456,
:ssh_host => 'example.com'
)
- @tunnel.ssh_tunnel_command_without_stall.should == "ssh -f -L 123:127.0.0.1:456 example.com"
+ @tunnel.ssh_tunnel_command_without_stall.should == "ssh -p 22 -f -L 123:127.0.0.1:456 example.com"
end
it "combines the tunnel command without stall and the stall command into the final command" do
@@ -119,4 +119,29 @@
command.should match(/grep/)
command.should match(/ssh command/)
end
+
+ describe "connecting to ssh service on alternative port" do
+
+ before do
+ @tunnel_with_ssh_port = Rush::SshTunnel.new('spec.example.com:222')
+ @tunnel_with_ssh_port.stub!(:config).and_return(mock_config_start)
+ @tunnel_with_ssh_port.stub!(:display)
+ end
+
+ it "recognizes alternative ssh port given in the real_host string" do
+ @tunnel_with_ssh_port.real_port.should == "222"
+ end
+
+ it "sets port for ssh commands" do
+ @tunnel_with_ssh_port.should_receive(:tunnel_options).at_least(:once).and_return(
+ :local_port => 123,
+ :remote_port => 456,
+ :ssh_host => 'example.com'
+ )
+ command = @tunnel_with_ssh_port.ssh_tunnel_command_without_stall
+ command.should match(/-p 222/)
+ end
+
+ end
+
end
Something went wrong with that request. Please try again.