Re: Linux how to manage passwords -automatically change password on linux servers (277 Views)
Reply
Occasional Contributor
gjajuga
Posts: 3
Registered: ‎09-28-2011
Message 1 of 3 (308 Views)

Linux how to manage passwords -automatically change password on linux servers

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.

 

Honored Contributor
Matti_Kurkela
Posts: 6,271
Registered: ‎12-02-2001
Message 2 of 3 (301 Views)

Re: Linux how to manage passwords -automatically change password on linux servers

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:

user1:password1
user2:password2

 etc.

 

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".

MK
Honored Contributor
VK2COT
Posts: 921
Registered: ‎01-17-2006
Message 3 of 3 (277 Views)

Re: Linux how to manage passwords -automatically change password on linux servers

Hello,

 

Matti gave you a simple and good advice.

 

On Linux, there are other nice ways to change password to "newpass"

for user "username".

 

For example:

 

# 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:

 

http://www.circlingcycle.com.au/Unix-sources/add-batch-Unix-accounts.pl.txt

 

... 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

 

 

 

VK2COT - Dusan Baljevic
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.