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', assword => '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', assword => 'testpwd') do |ssh|
ssh.forward.local(22004, "remoteserver", 22)
ssh.loop
end
Net::SSH.start('localhost', 'remoteuser', assword => 'remotepwd', ort => 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.
Net::SSH.start('middleserver', 'testuser', assword => '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', assword => 'testpwd') do |ssh|
ssh.forward.local(22004, "remoteserver", 22)
ssh.loop
end
Net::SSH.start('localhost', 'remoteuser', assword => 'remotepwd', ort => 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.