Using net:ssh

Hello,
what I want to do is the following:
- ssh into a remote machine (let's call it 'frontend')
- from the front-end, ssh into another machine (call it node-A)

So far, i was only able to perform the first step:

require 'rubygems'
require 'net/ssh'

def do_run_introducer(session)
  session.open_channel do |channel|
    channel.on_data do |ch, data|
      puts data
    end
   channel.exec "ls" #to verify that i'm actually logged in..
  end
end

Net::SSH.start( 'remote-machine-address', my-user-name' ) do |
session>
  do_run_introducer session
  #do_run_peers session
session.loop
end

Any help is very appreciated

I've not used the Net::SSH library personally, so I can't give any
specific help; but you might take a look through the code for
Capistrano (http://rubyforge.org/projects/capistrano\). IIRC, it
supports tunneling an SSH connection through a "frontend" machine, so
you may be able to figure it out by browsing the source.

···

On Feb 19, 5:14 am, Valerio Schiavoni <valerio.schiav...@gmail.com> wrote:

what I want to do is the following:
- ssh into a remote machine (let's call it 'frontend')
- from the front-end, ssh into another machine (call it node-A)

--
Regards,

John Wilger

Use port forwarding to tunnel a connection through the front end to the
SSH port on the node behind it. Then call a second SSH session on the
tunneled port.

See http://net-ssh.rubyforge.org/chapter-6.html for port forwarding.

HTH,

Felix

···

On Tue, 2008-02-19 at 22:15 +0900, Valerio Schiavoni wrote:

Hello,
what I want to do is the following:
- ssh into a remote machine (let's call it 'frontend')
- from the front-end, ssh into another machine (call it node-A)

So far, i was only able to perform the first step:

require 'rubygems'
require 'net/ssh'

def do_run_introducer(session)
  session.open_channel do |channel|
    channel.on_data do |ch, data|
      puts data
    end
   channel.exec "ls" #to verify that i'm actually logged in..
  end
end

Net::SSH.start( 'remote-machine-address', my-user-name' ) do |
session>
  do_run_introducer session
  #do_run_peers session
session.loop
end

Any help is very appreciated

I'm not sure if Net::SSH supports this, but basically what you want is
this:

    $ ssh -f -L 1234:remote_host:22 proxy_host < /dev/null &> /dev/null &

    $ ssh -p 1234 localhost

where "1234" is a number you pick. It will be the port on the client
machine that you can use to initiate a SSH connection to the remote
machine (remote_host). Note that "remote_host" will be resolved by
"proxy_host", not by the client.

I'd suggest you try it first on the command line and once you get it
working wrap it with Ruby.

HTH,

Marcelo

···

On Feb 19, 2008 7:15 AM, Valerio Schiavoni <valerio.schiavoni@gmail.com> wrote:

what I want to do is the following:
- ssh into a remote machine (let's call it 'frontend')
- from the front-end, ssh into another machine (call it node-A)