Hey all.. I''m having a problem where my script works as a normal
user, but when I try to do it as root, it fails.
I created a sample script that exhibits the behavior. I know
normally I wouldn''t need to exit the shell, but I''m doing that
in the
example to illustrate the problem - my real world application has
different methods using a passed in session object.
Here''s the script:
#!/usr/bin/ruby
require ''rubygems''
require ''net/ssh''
# session = Net::SSH.start( ''localhost'',
''local'', :paranoid =>
false)
session = Net::SSH.start( ''localhost'',
''root'', :paranoid =>
false)
shell = session.shell.sync
out = shell.send_command("whoami")
print out.stdout
shell.exit
shell = session.shell.sync
out = shell.send_command("date")
print out.stdout
shell.exit
Here''s an example run as root (ie, the error):
sinnoh:~ local$ ./minitest.rb
Password:
root
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/
gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/shell.rb:98:in
`send_data'': channel not open (RuntimeError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/
usr/lib/ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/
sync.rb:91:in `send_data''
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/
usr/lib/ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/
sync.rb:56:in `send_command''
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/
usr/lib/ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/
sync.rb:106:in `method_missing''
from ./minitest.rb:16
Any ideas? If I run as a normal user (local in the above example)
the command completes successfully. I''ve got a couple of workarounds
I don''t like, I can do a new session each time, or not use SyncShell.
Thanks!
- Josh
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://rubyforge.org/pipermail/net-ssh-users/attachments/20070817/d3bca594/attachment.html
This might not be related to net/ssh at all. Check your destination host''s sshd.conf, if it allows root to log in or not. The default (for security reasons) is to disallow root logins over ssh. -Vivek On 16/08/07, Josh Durham <joshdurham at mac.com> wrote:> Hey all.. I''m having a problem where my script works as a normal user, but > when I try to do it as root, it fails. > > I created a sample script that exhibits the behavior. I know normally I > wouldn''t need to exit the shell, but I''m doing that in the example to > illustrate the problem - my real world application has different methods > using a passed in session object. > > Here''s the script: > #!/usr/bin/ruby > require ''rubygems'' > require ''net/ssh'' > > # session = Net::SSH.start( ''localhost'', ''local'', :paranoid => false) > session = Net::SSH.start( ''localhost'', ''root'', :paranoid => false) > > shell = session.shell.sync > out = shell.send_command("whoami") > print out.stdout > shell.exit > > shell = session.shell.sync > out = shell.send_command("date") > print out.stdout > shell.exit > > Here''s an example run as root (ie, the error): > sinnoh:~ local$ ./minitest.rb > Password: > root > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/shell.rb:98:in > `send_data'': channel not open (RuntimeError) > from > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/sync.rb:91:in > `send_data'' > from > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/sync.rb:56:in > `send_command'' > from > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/sync.rb:106:in > `method_missing'' > from ./minitest.rb:16 > > > Any ideas? If I run as a normal user (local in the above example) the > command completes successfully. I''ve got a couple of workarounds I don''t > like, I can do a new session each time, or not use SyncShell. > > Thanks! > - Josh > _______________________________________________ > Net-ssh-users mailing list > Net-ssh-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/net-ssh-users >
It does.. if you look in the sample output, the ''whoami'' gets run. It''s the subsequent closing of the shell and reopening it that fails. I can also close the shell, and try to do a process.open, and it will fail with error 254. - Josh On 17 Aug 2007, at 03:39, Vivek Nallur wrote:> This might not be related to net/ssh at all. Check your destination > host''s sshd.conf, if it allows root to log in or not. The default (for > security reasons) is to disallow root logins over ssh. > > -Vivek > > On 16/08/07, Josh Durham <joshdurham at mac.com> wrote: >> Hey all.. I''m having a problem where my script works as a normal >> user, but >> when I try to do it as root, it fails. >> >> I created a sample script that exhibits the behavior. I know >> normally I >> wouldn''t need to exit the shell, but I''m doing that in the example to >> illustrate the problem - my real world application has different >> methods >> using a passed in session object. >> >> Here''s the script: >> #!/usr/bin/ruby >> require ''rubygems'' >> require ''net/ssh'' >> >> # session = Net::SSH.start( ''localhost'', ''local'', :paranoid >> => false) >> session = Net::SSH.start( ''localhost'', ''root'', :paranoid => >> false) >> >> shell = session.shell.sync >> out = shell.send_command("whoami") >> print out.stdout >> shell.exit >> >> shell = session.shell.sync >> out = shell.send_command("date") >> print out.stdout >> shell.exit >> >> Here''s an example run as root (ie, the error): >> sinnoh:~ local$ ./minitest.rb >> Password: >> root >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ >> ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/ >> shell.rb:98:in >> `send_data'': channel not open (RuntimeError) >> from >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ >> ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/sync.rb: >> 91:in >> `send_data'' >> from >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ >> ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/sync.rb: >> 56:in >> `send_command'' >> from >> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ >> ruby/gems/1.8/gems/net-ssh-1.1.2/lib/net/ssh/service/shell/sync.rb: >> 106:in >> `method_missing'' >> from ./minitest.rb:16 >> >> >> Any ideas? If I run as a normal user (local in the above example) >> the >> command completes successfully. I''ve got a couple of workarounds >> I don''t >> like, I can do a new session each time, or not use SyncShell. >> >> Thanks! >> - Josh >> _______________________________________________ >> Net-ssh-users mailing list >> Net-ssh-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/net-ssh-users >> > _______________________________________________ > Net-ssh-users mailing list > Net-ssh-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/net-ssh-users