From: otaku Date: 2004-09-11T22:30:00+09:00 Subject: Net-SSH Threaded PortForward Script Problems Greetings to all attempting to get a working script here that portforwards across multiple hosts and executes commands on the final host in the hops i located suggested design pattern posted by Jamis Buck the developer of the ruby net-ssh module the following code seems to be syntatically correct if anyone else has time to test the following script please provide some feedback i am not sure if i simply do not have the ssh server setup correctly on all systems along the hop path i have in sshd_config AllowTcpForwarding yes when i run the below code i get the following error messages in my ssh log file on the system the script is started from which leads me to believe the script is not even portforwarding to the first hop in the script tail -f /var/log/ssh.log ------- Sep 11 08:02:16 falcon1 sshd[12308]: Connection from ::ffff:127.0.0.1 port 39495 Sep 11 08:02:16 falcon1 sshd[12308]: Did not receive identification string from ::ffff:127.0.0.1 ------- when i placed the code in irb and the code is running into problems at this point in the script which is the final hop in the code the error message is Connection Refused Authentication error which again leads me to believe the script is not opening the tcp portforwarding gateways to facilitate the hops properly -------------- Net::SSH.start( 'localhost', 1236, 'jello', 'passwd' ) do |session| result = session.exec("hostname") puts result.data, "\n\n" result = session.exec("date") puts result.data, "\n\n" result = session.exec("uptime") puts result.data, "\n\n" end -------------- when i run the script i get the following error message: ------- ../threads_ssh.rb /usr/local/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:132:in `initialize': Connection refused - connect(2) (Errno::ECONNREFUSED) from /usr/local/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:132:in `open' from /usr/local/lib/ruby/site_ruby/1.8/net/ssh/transport/session.rb:132:in `initialize' from /usr/local/lib/ruby/site_ruby/1.8/net/ssh.rb:175:in `new' from /usr/local/lib/ruby/site_ruby/1.8/net/ssh.rb:175:in `open' from /usr/local/lib/ruby/site_ruby/1.8/net/ssh.rb:93:in `start' from ./threads_ssh.rb:36 --------- NOTE i have other scripts using the net-ssh ruby module that are working so i know this is not a problem with openssl it seems to be server side sshd_config problem or something along those lines as stated before if anyone can test on their end and post any ideas greatly appreciated and a thanks to everyone in advance BEGIN CODE 4 host Hop ---------- #!/usr/local/bin/ruby require 'thread' require 'net/ssh' require 'net/ssh/service/forward' threads = [] t = Thread.new do Net::SSH.start( 'host1', 'jello', 'pass' ) do |session| mgr = PortForwardManager.new( session ) mgr.forward_local( 1234, 'host2', 22 ) session.main_loop end end t = Thread.new do Net::SSH.start( 'localhost', 1234, 'jello', 'pass' ) do |session| mgr = PortForwardManager.new( session ) mgr.forward_local( 1235, 'host3', 22 ) session.main_loop end end t = Thread.new do Net::SSH.start( 'localhost', 1235, 'jello', 'pass' ) do |session| mgr = PortForwardManager.new( session ) mgr.forward_local( 1236, 'host4', 22 ) session.main_loop end end Net::SSH.start( 'localhost', 1236, 'jello', 'passwd' ) do |session| result = session.exec("hostname") puts result.data, "\n\n" result = session.exec("date") puts result.data, "\n\n" result = session.exec("uptime") puts result.data, "\n\n" end threads.push( t ) --------- END CODE