Bulk Modify system user passwords using the CHPASSWD command

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.