Net::SSH forward local port


H

hartj659

I'm trying to programmatically configure an ssh local port forward through a middle server, then run some commands to a remote ssh server on the far end. I created this ruby script:

Net::SSH.start('middleserver', 'testuser', :password => 'testpwd') do |ssh|
ssh.forward.local(22004, "remoteserver", 22)
ssh.loop
end

After running this script, I ran this on the command line:

ssh [email protected] -p 22004 "hostname"

Works.

Then I tried this:

Net::SSH.start('middleserver', 'testuser', :password => 'testpwd') do |ssh|
ssh.forward.local(22004, "remoteserver", 22)
ssh.loop
end

Net::SSH.start('localhost', 'remoteuser', :password => 'remotepwd', :port => 22004) do |ssh|
output = ssh.exec!("hostname")
print output
end

This does not work. I guess this is a naive implementation.

Any suggestions on how I should code this so I can forward commands from my localhost port to the remote ssh server?

Thanks for your suggestions.
 
Ad

Advertisements


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

Top