Shell script first-Custom create user and batch create user

Source: Internet
Author: User
Tags stdin

Shell Script First-Custom create user and batch create user

1. build Linux users with shell scripts

# vim/root/user.sh

#!/bin/bash

#通过脚本自定义创建用户

read-p " Please enter the user name you want to create : " $

Useradd $

read-p " Please set the user password: " $

Echo " $ " | passwd--stdin $ >/dev/null

#/root/user.sh or # cd/root #./user.sh or #bash user.sh or #. user.sh

#####################################################################

2. create a batch of Linux users with scripts

# vim/root/piuser.sh

#!/bin/bash

#通过脚本批量创建用户

prefix= "Stu" : Define user name prefix

I=1

While [$i-le 20]

Do

useradd ${prefix} $i : Added username: prefix + number

echo "123456" | passwd--stdin ${prefix} $i &>/dev/null

or userdel-r ${prefix} $i &>/dev/null: delete users in bulk

let i++

D One

  or Create user stu1 to stu50, specify Group as student group! Each user needs to set a different password!

#!/bin/bash
For i in ' seq 1 50 '
Do
useradd-g Student Stu$i ;  
echo stu$i | passwd stu$i--stdin
Done


Shell script first-custom create user and bulk create user

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.