set user password none-interactively in unix 18 April 2017
For system administrators, it’s a common task to set user’s password. Often we hope that we could do that without user interaction. In Linux or AIX, typically, we would write a shell script like this:
However, if you were in a HPUX system, you will find neither chpasswd
nor passwd --stdin
is available. So, how can we set user password in HPUX shell script?
After searching around, I got a perl script to generate encrypted password.
…run as:
…the output will be an encrypted password suitable for use with useradd
and usermod
.
The perl script above is too obscure for me, though it do work. More detailed information could be found by man 3 crypt
. After reading that, you should know what’s going on.
To generate encrypted password, the key is to call the crypt(key, salt)
function. Here is my own mypwgen
of python version, which I think is more readable.
Alternatively, there is another quick and dirty choice.
All the methods above can be easily adopted to Linux/AIX too. By the way, usermod -p
can also be used to recover password, if you have a backup.
blog comments powered by Disqus