Using net:ssh

V

Valerio Schiavoni

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
 
J

John Wilger

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/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.
 
F

fw

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/chapter-6.html for port forwarding.

HTH,

Felix
 
M

Marcelo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top