Linux changes passwords through shell scripts

Source: Internet
Author: User

Interactively change password 1. SSH remote to the host; 2. Switch to root account;

[generally switch to root for password modification, if the ordinary user to modify their own password, to enter the original password, and then the new password to meet the complexity of the OK];

3. passwd username

Use passwd username to modify the username password;
Using this command, you will be prompted to enter the interactive interface, the password can be entered.

To modify a password using a script

Many times we may need to remotely execute the script on the server to modify the account password, there is no way to interact.
There are two ways to change your password at this point:

Mode 1:
echo "password" | passwd testuser --stdin > /dev/null 2>&1
Mode 2:
echo testuser:password|chpasswd

Note:

    1. Double quotes for cipher strings, optional, see above 方式1 and 方式2 examples

    2. If the password contains a $ character, it needs to be escaped with a backslash, such as:

echo testuser:password\$|chpasswd

转自1190000003866142 特别感谢他在我职业生涯对我的帮助。

Linux changes passwords through shell scripts

Related Article

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.