03-10-2014 05:02 AM
How to easily manage your passwords on the Linux server?
I wonder how or what tool it was good to change password on linux servers, a time to change the password on 100 servers.
03-10-2014 05:43 AM
Most Linux distributions include a "chpasswd" tool, which is useful when changing a large number of passwords at once.
First, you create a file which contains one line for each user whose password you wish to change, like this:
The passwords can be either clear-text or encrypted (hashed): if you encrypt the password, you must use the -e option with the chpasswd command.
Then, you pipe this file to the chpasswd command.
If you have set up SSH keys or some other method that allows you to run commands on remote hosts as root without typing the password each time, you could automate this with a small shell script, like this:
#!/bin/sh MACHINELIST=machines.txt PASSWORDFILE=passwords.txt exec < $MACHINELIST while read MACHINE do ssh root@$MACHINE chpasswd < $PASSWORDFILE RESULT=$? if [ $RESULT -ne 0 ] then echo "Error $RESULT reported with machine $MACHINE, continuing..." >&2 fi done
The above scripts needs a list of machines as "machines.txt" and the passwords file for the chpasswd command as "passwords.txt".
03-14-2014 04:38 AM
Matti gave you a simple and good advice.
On Linux, there are other nice ways to change password to "newpass"
for user "username".
# echo newpass | passwd --stdin username
If you want to automate the whole process, maybe you get some ideas from my Perl script
for adding batch users accross five operating systems:
... and while we are at it, if you want pseudo-random passwords,
here are some ideas:
# < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c8 # date '+.%N' | md5sum | cut -c1-8 # openssl rand -base64 32 | head -c8 # makepasswd # shuf -n1 /usr/share/dict/words Linux has almost unlimited possibilities