Linux Bulk Create user and bulk delete users

Source: Internet
Author: User
Tags stdin

Linux Bulk Create user and bulk delete users

The following is a batch creation of users:

#首先我们需要创建一个xxx. txt file, write the user we created in this text, and note that each user needs to be wrapped.

Vim User.txt

User1

User2

User3

#创建一个xxx the. Sh shell script, and then use the For loop to iterate through the created User.txt, which is the shell script:

#!/bin/bash

#我这里是把shell脚本和txt文件创建在同一个目录下, if you are not in the same directory, be aware of the following path

For the user in ' Cat user.txt '

Do

Useradd $user

#这里的passwd--stdin means: Non-interactive, direct input password

echo "123" | passwd--stdin $user

echo "The User Useradd success!"

Done

The following is a bulk delete user

#看了以上的批量创建用户, then it's easy for the next batch to delete the user!

#原理基本上是一样的, it's just a different order, I don't have much to explain.

#以下是shell脚本

#!/bin/bash

For the user in ' Cat user.txt '

Do

Userdel-r $user

echo "The User deletc success!"

Done

Linux Bulk Create user and bulk delete users

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.