Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net-ssh does not handle non-multiplexed ssh connections #121

Closed
jakerobinson opened this issue Sep 11, 2013 · 8 comments
Closed

net-ssh does not handle non-multiplexed ssh connections #121

jakerobinson opened this issue Sep 11, 2013 · 8 comments

Comments

@jakerobinson
Copy link

When an opensshd server is set to MaxSessions 1, disabling multiplexing, every other exec!() command fails with open failed(1)

/Users/jrobinson/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.6.8/lib/net/ssh/connection/channel.rb:524:in `do_open_failed'
/Users/jrobinson/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.6.8/lib/net/ssh/connection/session.rb:545:in `channel_open_failure'
/Users/jrobinson/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.6.8/lib/net/ssh/connection/session.rb:459:in `dispatch_incoming_packets'
/Users/jrobinson/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.6.8/lib/net/ssh/connection/session.rb:216:in `preprocess'
/Users/jrobinson/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.6.8/lib/net/ssh/connection/session.rb:200:in `process'
/Users/jrobinson/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.6.8/lib/net/ssh/connection/session.rb:164:in `block in loop'
/Users/jrobinson/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.6.8/lib/net/ssh/connection/session.rb:164:in `loop'
/Users/jrobinson/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.6.8/lib/net/ssh/connection/session.rb:164:in `loop'
/Users/jrobinson/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.6.8/lib/net/ssh/connection/channel.rb:269:in `wait'
/Users/jrobinson/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.6.8/lib/net/ssh/connection/session.rb:358:in `exec!'
@delano
Copy link
Collaborator

delano commented Sep 11, 2013

Thanks for the report. The project is in maintenance mode but if someone wants to submit a pull request for this I'll happily merge it in.

@mfazekas
Copy link
Collaborator

mfazekas commented Mar 6, 2016

I might misunderstood this issue but you should be able to open different connection and do just one exec per connection

@mfazekas mfazekas closed this as completed Mar 6, 2016
@davidpowerwpe
Copy link

I also ran in to this issue when trying to use Serverspec to talk to a server with MaxSession set to 1.

@davidpowerwpe
Copy link

@jakerobinson did you ever resolve / get around this issue?

@jakerobinson
Copy link
Author

@davidpowerwpe Sadly I never had a chance to fix it in net-ssh. I ended up defaulting MaxSessions to 10 by deleting the line. We decided the very small security precaution was not worth breaking most of our automation.

@mfazekas
Copy link
Collaborator

mfazekas commented Jun 9, 2017

Guys if you can demonstrate the issue in a small net-ssh script to reproduce the issue that would make stuff much more straightforward.

@jakerobinson
Copy link
Author

jakerobinson commented Jun 9, 2017

Thanks @mfazekas, I was wrong not to include that when I first submitted this issue.

Setup: Add the line MaxSessions 1 to the remote machine's /etc/ssh/sshd_config and restart sshd.

Run the following with the correct host and credentials:
https://gist.github.com/jakerobinson/827e4fec5b9e5ff45b68997006f1aceb

Expected result (achieved when MaxSessions 10):

2.0.0-p576 :010 >   Net::SSH.start('1.2.3.4', 'root', :password => "foobar") do |ssh|
2.0.0-p576 :011 >       for i in 0..9
2.0.0-p576 :012?>         output = ssh.exec!("hostname")
2.0.0-p576 :013?>         puts output
2.0.0-p576 :014?>       end
2.0.0-p576 :015?>   end
flower
flower
flower
flower
flower
flower
flower
flower
flower
flower
 => 0..9 

Actual result (MaxSessions 1):

Net::SSH::ChannelOpenFailed: open failed (1)
	from /Users/jrobinson/.rvm/gems/ruby-2.0.0-p576/gems/net-ssh-2.9.4/lib/net/ssh/connection/channel.rb:544:in `do_open_failed'
	from /Users/jrobinson/.rvm/gems/ruby-2.0.0-p576/gems/net-ssh-2.9.4/lib/net/ssh/connection/session.rb:560:in `channel_open_failure'
	from /Users/jrobinson/.rvm/gems/ruby-2.0.0-p576/gems/net-ssh-2.9.4/lib/net/ssh/connection/session.rb:474:in `dispatch_incoming_packets'
	from /Users/jrobinson/.rvm/gems/ruby-2.0.0-p576/gems/net-ssh-2.9.4/lib/net/ssh/connection/session.rb:222:in `preprocess'
	from /Users/jrobinson/.rvm/gems/ruby-2.0.0-p576/gems/net-ssh-2.9.4/lib/net/ssh/connection/session.rb:206:in `process'
	from /Users/jrobinson/.rvm/gems/ruby-2.0.0-p576/gems/net-ssh-2.9.4/lib/net/ssh/connection/session.rb:170:in `block in loop'
	from /Users/jrobinson/.rvm/gems/ruby-2.0.0-p576/gems/net-ssh-2.9.4/lib/net/ssh/connection/session.rb:170:in `loop'
	from /Users/jrobinson/.rvm/gems/ruby-2.0.0-p576/gems/net-ssh-2.9.4/lib/net/ssh/connection/session.rb:170:in `loop'
	from /Users/jrobinson/.rvm/gems/ruby-2.0.0-p576/gems/net-ssh-2.9.4/lib/net/ssh/connection/channel.rb:269:in `wait'
	from /Users/jrobinson/.rvm/gems/ruby-2.0.0-p576/gems/net-ssh-2.9.4/lib/net/ssh/connection/session.rb:365:in `exec!'
	from (irb):15:in `block (2 levels) in irb_binding'
	from (irb):14:in `each'
	from (irb):14:in `block in irb_binding'
	from /Users/jrobinson/.rvm/gems/ruby-2.0.0-p576/gems/net-ssh-2.9.4/lib/net/ssh.rb:215:in `start'
	from (irb):13
	from /Users/jrobinson/.rvm/rubies/ruby-2.0.0-p576/bin/irb:12:in `<main>'

@mfazekas mfazekas reopened this Jun 24, 2017
@mfazekas
Copy link
Collaborator

@jakerobinson

This doesn't works for me

Net::SSH.start('1.2.3.4', 'root', :password => "foobar") do |ssh|
  for i in 0..9
   output = ssh.exec!("hostname")
   puts output
 end
end

But this does

Net::SSH.start('1.2.3.4', 'root', :password => "foobar") do |ssh|
  for i in 0..9
   output = ssh.exec!("hostname")
   puts output
   ssh.process # !!!
 end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants