How the CHPASSWD command works:
Read the user's name and password from the system's standard input and use this information to update the user's password that already exists on the system!
Grammar:
1:# echo User name: password | chpasswd
2:# CHPASSWD < Doiido.txt
Related parameters:
-E: If the-e option is used, the password will be passed only in an encrypted manner
-E,--encrypted supplied passwords is encrypted
If the-e option is not used, the password is passed as clear text
Precautions
1: User name must be a user that already exists on the system
2: Normal user does not have permission to use this command
3: If the input file is passed unencrypted, please encrypt the file appropriately.
4: Command file cannot have blank line
Instance
1, directly modify the CentOS user's password is CENTOS1
# echo CENTOS:CENTOS1 |chpasswd
2. Use the user name password in password.txt to modify the password of the corresponding user in bulk
2.1: First build instruction file password.txt (TXT file format = [username:passwd])
# VI Password.txt
Test1:redhat123
Test2:redhat123
2.2: Transfer the contents of Password.txt to the chpasswd instruction to modify the corresponding user's password
# CHPASSWD < Password.txt
3, let ordinary users use CHPASSWD
The default normal user does not have CHPASSWD permissions, but can modify the command file permissions by modifying the
# chmod 4755/USR/SBIN/CHPASSWD
So that ordinary users can use CHPASSWD to modify the password
4. Batch remote Modify server password
For example, using Saltstack or ansible to bulk modify the managed-side server password
First to configure the server and client SSH login authentication without password, and then batch modification
A simple shell script:
Cat alter_pwd.sh
#!/bin/bash
Ips= ' Cat server_name.cfg '
For IP in $ips
Do
SSH $ip "echo ' root:123456798 ' |chpasswd"
If [$?-eq 0]
Then
Echo-e "$ip ' s password updated \033[32m successful.\033[0m"
Else
Echo-e "$ip ' s password updated \033[31m failed!!! \033[0m "
Fi
Done
Note: The server_name.cfg file is a controlled segment server IP address (one line of IP)
Bulk Modify system user passwords using the CHPASSWD command