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 remoteuser@localhost -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.
 

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,818
Messages
2,569,732
Members
45,691
Latest member
Dick331194

Latest Threads

Top