1833776 Members
2317 Online
110063 Solutions
New Discussion

updating root password

 
Steve Massey_1
Frequent Advisor

updating root password

Hi

I am trying to pass a new password of the ROOT account from a script rub by ROOT

ie simply in a script using th following

passwd root

It doesn't like it. Any ideas ??

Steve
7 REPLIES 7
Benoit MARC
Occasional Advisor

Re: updating root password

Hi

passwd(1) command do not accept passwd on the command line. For security purpose, I guess.
And it requires entering the new passwd twice.

To be able to do what you want, I have write your own program that will update the passwd file, using getpw[ent|name|uid](3) and putpwent(3) functions.

regards
Steve Massey_1
Frequent Advisor

Re: updating root password

Any idea on the format of these calls within a script??


Or an example

Thanks

Steve
Dale McNamara
Frequent Advisor

Re: updating root password

These are 'C' functions, and you would need to create a 'C' program in order to use.

This would probably be a better option so that the password is not in plain text in the script.

Check the man pages on the putpwent(3C).
Alan Riggs
Honored Contributor

Re: updating root password

It is also possible to use an expect script to update passwords. Of course, you have to have expect and tcl installed on your system, first.
Sandro Schaer
Occasional Advisor

Re: updating root password

hi there
there's another way to solve your problem. i'm running an terminal emulator on my pc called PWACCESS . with this tool it's possible to create a script handling events/actions. i'd solve your problem with following script :
waitfor "login:"
send "root"
waitfor "Password:"
send "hp" (send root's password)
waitfor "hp03a:/#" (system prompt)
send "passwd"
waitfor "New password:"
send "xyz" (send new password"
waitfor "Re-enter..."
send "xyz"

This should work, but you would have to modify the password in this script everytime you run it (not very comfortable...)

unix and oracle administrator
Ralph Grothe
Honored Contributor

Re: updating root password

Perl offers the same system functions (e.g. getpwent, getpwnam, setpwnam etc.) as the C libs.
But I would consider them much easier to use from Perl, especially when it comes to parsing of text files.
If you have Perl on your system (BTW HP-UX ships a very dated Perl 4.X under /usr/contrib/bin, which should be superseded by a recent Perl 5.6 ;-) consult the POD

$ perldoc perlfunc

Perl even offers an Expect Module from CPAN, which is modelled after the TCL expect, in case you need to run jobs that require some kind of user interaction.
Madness, thy name is system administration
RikTytgat
Honored Contributor

Re: updating root password

Hi,

You can of course do it in C.

Attached to this reply you find a piece of code that changes the password of a user. The code works on trusted an non trusted systems.

Hope this helps,
Rik