Linux batch User Creation and deletion tutorials, linux User Creation tutorials

Source: Internet
Author: User

Linux batch User Creation and deletion tutorials, linux User Creation tutorials

Create users in batches as follows:

First, you need to create a xxx.txt file and write the user you want to create in this text. Note: each user writes a line break.

Vim user.txt

User1

User2

User3

# Create a xxx. sh shell script, and then use the forcycle to traverse the created user.txt. The following is a shell script:

#! /Bin/bash

# Here I create shell scripts and txt files in the same directory. If they are not in the same directory, note the path

For user in 'cat user.txt'

Do

Useradd $ user

# Passwd -- stdin indicates no interaction. Enter the password directly.

Echo $ user | passwd -- stdin $ user & >>/dev/null

Echo "The user useradd success! "

Done

Delete users in batches

# After reading the above batch create users, it is easy to delete users in batches!

# The principle is basically the same, but a command is different, so I will not explain it much.

# The following is a shell script

#! /Bin/bash

Grep "/bin/bash"/etc/passwd | grep-v "root" | cut-d ":"-f 1> 2.txt

For user in $ (cat./2.txt)

Do

Userdel-r $ user

Echo "del $ user OK"

Done

Rm-rf 2.txt

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.