Batch add users in Linux

Source: Internet
Author: User
Tags ftp login
In Linux, add users in batches-Linux Enterprise Application-Linux server application information. The following is a detailed description. Learning reference.

1. Why do users need to be added in large quantities in Linux;

When do we need to add a large number of users? Sometimes we need to have dozens or more users perform the same or similar tasks on the host. For example, if we want to add a bunch of ftp users at the same time, these ftp users belong to the same group, but they are not allowed to log on to the server through a terminal or remote connection. Sometimes we may want to teach. For example, we have 50 students, and each student has an independent user name on the server and can log on to the system, it can also manage its own accounts or complete some jobs with its own permissions;

2. Add a batch of users in Linux;

The process of adding users in batch is to import a file written in strict accordance with the/etc/passwd format through newusers to add users, then, import the user password file through chpasswd to complete the process of batch updating user passwords;

1. newusers tools for adding users in batches;

The usage is simple. newusers is followed by a file directly. The file format is the same as that of/etc/passwd;

Username 1: x: UID: GID: User Description: user's home directory: SHELL used

Example:

Win00: x: 520: 520:/home/win00:/sbin/nologin

Win01: x: 521: 521:/home/win01:/sbin/nologin

......

It is worth mentioning that for SHELL types, you can view all the shells on the host through chsh;

[Root @ localhost beinan] # chsh -- list

/Bin/sh

/Bin/bash

/Sbin/nologin

/Bin/ksh

/Bin/tcsh

/Bin/csh

/Bin/zsh

In addition to/sbin/nologin, other types of shells can log on to the system. Most of nologin is the SHELL used by virtual users. That is to say, although he is a system user, he has no permission to log on to the system; if you want to add such users, set the SHELL to/sbin/nologin, as shown in the preceding example;

For details about the username, UID, GID, and user's home directory, read the relevant reference documents;

2. chpasswd: Batch update of User Password tools;

The chpasswd tool is a tool used to update user passwords in batches. It is used to add the content of a file to/etc/shadow;

Chpasswd 3. Add User instances in batches;

1. First, create the user file and password file;

Create the userfile.txt file containing the new user, and set the userpwdfile.txt password for the new user;

[Root @ localhost ~] # Touch userfile.txt

[Root @ localhost ~] # Touch userpwdfile.txt

Then, open the userfile.txt file with the Administrative editor and add the following content;

Win00: x: 520: 520:/home/win00:/sbin/nologin

Win01: x: 521: 521:/home/win01:/sbin/nologin

Win02: x: 522: 522:/home/win02:/sbin/nologin

Win03: x: 523: 523:/home/win03:/sbin/nologin

Win04: x: 524: 524:/home/win04:/sbin/nologin

Win05: x: 525: 525:/home/win05:/sbin/nologin

Win06: x: 526: 526:/home/win06:/sbin/nologin

Win07: x: 527: 527:/home/win07:/sbin/nologin

Win08: x: 528: 528:/home/win08:/sbin/nologin

Win09: x: 529: 529:/home/win09:/sbin/nologin

The content format of the userfile.txt file is the same as that of/etc/passwd, which must be written in strict accordance with the/etc/passwd format. All users added above cannot log on to the system, but it can be used for ftp login, but you have to open it in the configuration file of the corresponding ftp server to allow local users to have read and write permissions; if you want to allow some of the above users to log on to the system, you can change the SHELL like/bin/bash;

Let's write the userpwdfile.txt content of the new password file; the username in the file must be the same as the userfile.txt username; that is to say, we first add users from win00 to win09, and now we need to update the password for these users; for example, below;

Win 00: 123456

Win01: 654321

Win02: 123321.

Win03: qweewq

Win04: google

Win05: adadwc

Win06: wsscee

Win07: xxec32

Win08: 543wew

Win09: 3ce3wf

2. Add users in batches through newusers and chpasswd;

[Root @ localhost ~] # Newusers userfile.txt

[Root @ localhost ~] # Chpasswd IV. postscript;

Even if user management is almost complete, I have written six articles so far. Although the quality is not very high, it can be called a comparison system. In the next few days, I want to write a file for Management. The progress is slow, but it is still stuck. Persistence is victory, isn't 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.