Linux/CentOS Shell script non-interactive Password Change

Source: Internet
Author: User

Linux/CentOS Shell script non-interactive Password Change

Today, when I wrote a shell script, I found that the user's password needs to be set and the password is set to interactive. This is obviously not good in the script, So I went online to search for information, two non-interactive password setting methods are found:

1. Use chpasswd

In fact, chpasswd uses the user to enter the 'user name: password' to change the passwords of a group of users. It is also a tool for changing passwords in batches. For details about the usage, see chpasswd usage.

Format: # echo Username: Password | chpasswd

For example, to add a bkjia account with a password of 123456, run the following command:

# Echo bkjia: 123456 | chpasswd

2. Use passwd and -- stdin combination

Passwd uses the terminal as the standard input by default, and -- stdin indicates that any file can be used as the standard input. The two combinations can directly change the password.

Format: # echo 'Password' | passwd -- stdin User Name

Add a bkjia account with the password 123456. The command is as follows:

# Echo '000000' | passwd -- stdin bkjia

In this way, the password can be changed in non-interactive mode, but export can be used for some embedded linux methods.

Shell programming

Replace Linux Shell Parameters

Shell for parameters

Pass Linux/Unix Shell parameters to SQL scripts

Introduction to parameter passing methods in Shell scripts

PASS command line parameters through Shell scripts

This article permanently updates the link address:

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.