In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to add users in bulk in the Linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
When do we need to add users in large quantities? Sometimes we need dozens or more users to perform the same or similar tasks on the host. For example, 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 in to the server through terminals or remotely. Sometimes we may be in order to teach, for example, we have 50 students, and each student has a unique user name on the server, can log in to the system, and can manage their own accounts or complete some homework under their own authority.
Batch user add process:
The process of adding users in batches is to add users by importing a file that strictly follows the writing format of / etc/passwd through newusers, and then to update users' passwords in batches by importing user password files through chpasswd.
1. Newusers tools for adding users in batches
Its use is very simple, newusers is followed directly by a file; the file format is the same as / etc/passwd format
User name 1:x:UID:GID: user description: user's home directory: SHELL used
For example:
The code is as follows:
Win00:x:520:520::/home/win00:/sbin/nologin
Win01:x:521:521::/home/win01:/sbin/nologin
.
What is worth mentioning is about the SHELL type. Check all the SHELL on the host, which can be viewed through chsh.
The code is as follows:
[root@localhost beinan] # chsh-- list
/ bin/sh
/ bin/bash
/ sbin/nologin
/ bin/ksh
/ bin/tcsh
/ bin/csh
/ bin/zsh
Except / sbin/nologin, all other types of SHELL can log in to the system; nologin is mostly a SHELL used by a virtual user, that is, although he is a system user, he does not have permission to log in to the system; if you want to add such a user, set his SHELL to / sbin/nologin, such as the example above; you can read the reference documentation for user name, UID, GID and the user's home directory
2. Chpasswd batch Update user password tool
The chpasswd tool is a tool that updates user passwords in batches and redirects the contents of a file to / etc/shadow
Chpasswd < file
However, the content of the document is not unagreed, it must be written in the following format, and there can be no blank lines.
User name: password
Username 1: password 1
Username 2: password 2
For example:
The code is as follows:
Win00:123456
Win01:654321
......
Add user instances in batch:
1. First, we create a user file and a password file
We want to create a file userfile.txt that contains the new user; another is the userpwdfile.txt that sets the password for the newly added user
The code is as follows:
[root@localhost ~] # touch userfile.txt
[root@localhost ~] # touch userpwdfile.txt
Then open the file userfile.txt with a text editor and add the following
The code is as follows:
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 userfile.txt file is the same as that of / etc/passwd, and it must be written strictly according to the format of / etc/passwd. None of the users added above can log in to the system, but they can be used for ftp login, but you have to open them in the configuration file of the corresponding ftp server so that local users have read and write access. If you want some of the users above to log in to the system, you can change the SHELL to / bin/bash; then we will write the password file userpwdfile.txt for the new users; the user name in this file should be the same as the userfile.txt user name; that is to say, we need to update the password for the users who first added win00 to win09, such as the following
The code is as follows:
Win00: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
The code is as follows:
[root@localhost ~] # newusers userfile.txt
[root@localhost ~] # chpasswd < userpwdfile.txt
This way, if you find that the clear password of the user can be found in / etc/passwd, you can map to the / etc/shadow filename with the following command
The code is as follows:
[root@localhost ~] # pwconv
This is the end of the content of "how to add users in bulk in the Linux system". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.