Quantcast
Channel: All System Administration posts
Viewing all articles
Browse latest Browse all 1179

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

$
0
0

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


Viewing all articles
Browse latest Browse all 1179

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>