Unable to change password using Net::SSH

(Amit Chitre) #1

Running on WinXP, ssh to Solaris. Tried using the shell as well as
popen3 channel method but doesn't work... just sits there spinning..
Let me know what I'm doing wrong, if it's even allowed

<--popen3 channel method-->
require 'net/ssh'

session = Net::SSH.start( 'myserver.com',
                  'user_id',
                  'old_password',
                  :auth_methods => %w(password keyboard-interactive) )

session.process.popen3( "passwd" ) do |input, output, error|
  [ "old_password", "new_password", "new_password" ].each do |passwords|
    input.puts passwords
    puts output.read
  end
end

session.close

<--shell method-->
require 'net/ssh'

session = Net::SSH.start( 'myserver.com',
                  'user_id',
                  'old_password',
                  :auth_methods => %w(password keyboard-interactive) )

shell = session.shell.sync

out = shell.pwd
p "Working Dir==>>" << out.stdout

out = shell.send_command( "passwd", <<CMD)
old_password
new_password
new_password
CMD

p out.stdout

shell.exit
session.close

···

=============

If this is not allowed, please suggest other options to change
passwords on unix servers in programmatic fashion.

Thanks ...

Amit

(Jamis Buck) #2

Amit,

I'm not sure why the methods you tried aren't working, but you might want to try just using channels directly. You can look at the source of the Command object (in SwitchTower) for an example that does this--you might even be able to grab the "open_channels" method of the object and tweak it slightly for your purposes:

   http://dev.rubyonrails.com/file/trunk/switchtower/lib/switchtower/command.rb

Good luck,

Jamis

···

On Aug 8, 2005, at 7:56 PM, Amit Chitre wrote:

Running on WinXP, ssh to Solaris. Tried using the shell as well as
popen3 channel method but doesn't work... just sits there spinning..
Let me know what I'm doing wrong, if it's even allowed