[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Using net:ssh

Valerio Schiavoni

2/19/2008 1:14:00 PM

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
3 Answers

John Wilger

2/19/2008 1:28:00 PM

0

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)

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/...). IIRC, it
supports tunneling an SSH connection through a "frontend" machine, so
you may be able to figure it out by browsing the source.

--
Regards,

John Wilger

Felix Windt

2/19/2008 1:45:00 PM

0

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
>

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/chap... for port forwarding.

HTH,

Felix


Marcelo

2/19/2008 2:05:00 PM

0

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)

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