Operating System - Linux
1753677 Members
5433 Online
108799 Solutions
New Discussion

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

 
gjajuga
Occasional Contributor

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.

 

2 REPLIES 2
Matti_Kurkela
Honored Contributor

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
VK2COT
Honored Contributor

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