# Using expect.rb to change a user's password in UNIX

**URL:** <https://www.ruby-forum.com/t/using-expect-rb-to-change-a-users-password-in-unix/110095>\
**Category:** Ruby\
**Created:** [July 23, 2007, 2:17am UTC](https://www.ruby-forum.com/t/using-expect-rb-to-change-a-users-password-in-unix/110095 "2007-07-23T02:17:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [July 23, 2007, 2:17am UTC](https://www.ruby-forum.com/t/using-expect-rb-to-change-a-users-password-in-unix/110095/1 "2007-07-23T02:17:01Z")

</div>

Hello World,

Today, I used a Korn Shell script and the UNIX version of expect to  
change a  
user password remotely.  
I would like to use the ruby.rb library to do the same.  
For instance, when you type, in UNIX,

passwd username  
It comes back asking to enter the PW.  
Once you enter it, it comes back asking you to enter it again.

How do I do this using the ruby expect.rb library?

We use this to change a userid on multiple systems at the same time.

Thank you,

Victor

---

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [July 23, 2007, 5:01am UTC](https://www.ruby-forum.com/t/using-expect-rb-to-change-a-users-password-in-unix/110095/2 "2007-07-23T05:01:18Z")

</div>

Victor R. wrote:

> Once you enter it, it comes back asking you to enter it again.
> 
> How do I do this using the ruby expect.rb library?
> 
> We use this to change a userid on multiple systems at the same time.
> 
> Thank you,
> 
> Victor

If the systems on which the passwords are to be changed are Linux, there  
is a “batch password change utility” called “chpasswd”. So your Ruby  
script can simply encrypt the passwords, generate an input file to  
“chpasswd”, and execute “chpasswd” as “root”.

---

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [July 23, 2007, 5:53am UTC](https://www.ruby-forum.com/t/using-expect-rb-to-change-a-users-password-in-unix/110095/3 "2007-07-23T05:53:01Z")

</div>

On Jul 22, 6:15 pm, “Victor R.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> How do I do this using the ruby expect.rb library?

I just went through this. You can use net-telnet (or net-ssh). See:

[http://groups.google.com/group/ruby-talk-google/browse\_frm/thread/96cabb08c34182c/77c0843d27e95dd3?lnk=gst&q=berger+password&rnum=1#77c0843d27e95dd3](http://groups.google.com/group/ruby-talk-google/browse_frm/thread/96cabb08c34182c/77c0843d27e95dd3?lnk=gst&q=berger+password&rnum=1#77c0843d27e95dd3)

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [July 23, 2007, 2:13pm UTC](https://www.ruby-forum.com/t/using-expect-rb-to-change-a-users-password-in-unix/110095/4 "2007-07-23T14:13:50Z")

</div>

Hi,

On 22-Jul-07, at 8:15 PM, Victor R. wrote:

> Once you enter it, it comes back asking you to enter it again.
> 
> How do I do this using the ruby expect.rb library?

I don’t know. I had to do something similar for scripting rsync over  
ssh, and just used the unix version of expect (using popen4 and a  
bash script I generated in Ruby). Very ugly, but expect usually is 🙂

Cheers,  
Bob

> We use this to change a userid on multiple systems at the same time.
> 
> Thank you,
> 
> Victor

* * *

Bob H. – tumblelog at http://  
www.recursive.ca/so/  
Recursive Design Inc. – weblog at [http://www.recursive.ca/](http://www.recursive.ca/)  
hutch  
[http://www.recursive.ca/](http://www.recursive.ca/) – works on [http://www.raconteur.info/](http://www.raconteur.info/)  
cms-for-static-content/home/

---

<div class="post-metadata">

**Author:** ![ribes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f4b2a3/32.png) [@ribes](https://www.ruby-forum.com/u/ribes)\
**Post date:** [July 23, 2007, 7:09pm UTC](https://www.ruby-forum.com/t/using-expect-rb-to-change-a-users-password-in-unix/110095/5 "2007-07-23T19:09:08Z")

</div>

The servers where I need to do this is AIX.  
We use one AIX server as the controlling server from which we sent a  
distributed request to execute certain script everywhere.  
The script, which exists on each server, executes as requested.

Thank you

Victor
