Two methods of changing passwords interactively in shell scripts _linux shell

Source: Internet
Author: User
Tags stdin

Today, when writing a shell script to find that you need to set the user's password, and set the password is interactive, so in the script is obviously not very good, so the Internet to find data, found the following two common way to set the password is not interactive:

1: Use CHPASSWD

CHPASSWD is actually through user input ' username: password ' To change a group of user's password, or a can batch modify the password tool, specific usage see CHPASSWD usage, here only do simple introduction

Format: # echo User name: password | chpasswd

Instance:

Add a Doiido account with a password of 123456

Copy Code code as follows:

# echo doiido:123456 | chpasswd

2: Use passwd and--stdin combinations

passwd default is to use the terminal as a standard input, and--stdin said that can use arbitrary files to do standard input, these two can be directly modified password

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

Instance:

Add a Doiido account with a password of 123456

Copy Code code as follows:

# echo ' 123456 ' | passwd--stdin Doiido

This enables you to modify the password in non-interactive mode, but some embedded Linux is not supported in either way, and you can use export to implement it.

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.