Unable to change password using Net::SSH

A

Amit Chitre

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
 
J

Jamis Buck

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,056
Members
48,769
Latest member
Clifft

Latest Threads

Top