Batch build Linux users with shell scripts

Source: Internet
Author: User
Tags stdin


Implementation requirements: Create user student1 to Student50, specify Group as student group! And each user needs to set a different password!
The script is implemented as follows:

#!/bin/bashfor i in ' seq 1 "do useradd-g student student$i; echo student$i | passwd student$i--stdin;done

Description: Linux under passwd parameters

--stdin

This option was used to indicate that passwd should read the new password from standard input, which can be a pipe.

so the way to automatically change user passwords under Linux is:

Echo password |passwd–stdin user name
"
-------------------Set the same password------------------------

#!/bin/bashpassword= "123456" for the USER in User1 user2 user3do useradd-m $USER echo-e "${password}\n${password}" | passwd $USERdone


"Description:
echo-n no newline output:
$echo-N "123"
$echo "456"
Final Output
123456
and not
123
456
ECHO-E Handling Special characters:
\ n Wraps and the cursor moves to the beginning of the line
OK, just such a simple script, you can batch generate accounts in the system. And the password is the same as the name of the account.
This is the use of the for Do statement.




This article is from "Linux rookie" blog, please be sure to keep this source http://490617581.blog.51cto.com/11186315/1765043

Batch build Linux users with 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.