In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces how to increase users in linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.
In linux, you can use the useradd command to add users, which is used to create a new user and add a new system user. The basic syntax format is "useradd [option] username".
The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.
In linux, you can use the useradd command to create a new user and add a new system user.
The basic format of this command is as follows:
[root@localhost ~] # useradd [option] user name
The options commonly used for this command and their respective meanings are shown in Table 1.
Table 1 useradd command common option meaning-u UID manually specifies the user's UID, pay attention to the range of UID (not less than 500). -d home directory manually specifies the user's home directory. The home directory must write an absolute path, and if you need to specify the home directory manually, be sure to pay attention to the permissions;-c user description manually specify the descriptive content of the fifth field of user information in the / etc/passwd file, which can be configured at will;-g group name manually specifies the user's initial group. Generally, the initial group of the user is the same as the user name, and the initial group is established by default when the user is created. Once specified manually, the system will no longer create this default initial group directory. The-G group name specifies the user's additional group. We add users to other groups, usually using additional groups;-s shell manually specifies the user's login Shell. The default is / bin/bash;-e date, which specifies the user's expiration date in the format of "YYYY-MM-DD". This is the eighth field of the / etc/shadow file;-o allows users to create the same UID. For example, execute the "useradd-u 0-o usertest" command to establish the user usertest, whose UID is the same as the root user's UID, and both force the establishment of the user's home directory when creating the user. This option is the default when establishing system users;-r create system users, that is, users whose UID is between 1mm and 499, for use by system programs. Because system users are mainly used to run the permissions configuration of the services required by the system, the creation of system users does not create a home directory by default.
In fact, the system has set a lot of default values for us, and we can successfully create users without using any options without special requirements. For example:
[root@localhost ~] # useradd lamp
This line of command means to create a normal lamp user.
Don't underestimate this simple command, it does the following:
Create a line of data related to the lamp user in the / etc/passwd file:
[root@localhost ~] # grep "lamp" / etc/passwdlamp:x:500:500::/home/lamp:/bin/bash
As you can see, the user's UID is calculated from 500. At the same time, the user's home directory is specified as / home/lamp/, by default. The login Shell of the user is / bin/bash.
A new line of data related to the lamp user password has been added to the / etc/shadow file:
[root@localhost ~] # grep "lamp" / etcram shadowlamp / EtcBash shadowlampVoule15710VOVOVOUR 99999V7
Of course, the user has not set a password, so the password field is "!!", which means that the user does not have a reasonable password and cannot log in normally. At the same time, the time field will be set according to the default value, for example, the password is valid for 99999 days, and the user will be prompted to "the password is about to expire" 7 days after the password expires.
Create a group in the / etc/group file that is exactly the same as the user name:
[root@localhost ~] # grep "lamp" / etc/grouplamp:x:500:
This group is used as the initial group for the new user.
Add a new line of password information related to the new group in the / etc/gshadow file:
[root@localhost ~] # grep "lamp" / EtcUnip gshadowlamp
Of course, we don't have a group password, so there is no password and no group administrator.
Create the user's home directory and mailbox by default:
[root@localhost] # ll-d / home/lamp/drwx- 3 lamp lamp 4096 January 6 00:19 / home/lamp/ [root@localhost] # ll / var/spod/mail/lamp-rw-rw---- 1 lamp mail 0 January 6 00:19 / var/spool/mail/lamp
Note that the permissions of these two files should be given to the lamp user.
Copy the configuration file from the / etc/skel directory to the home directory of the new user.
As you can see, the process of creating a user with the useradd command is to modify several files or directories related to the user, which have been described in detail in the previous chapter.
In addition to creating users by default, we can also customize the users we want to create ourselves using the various options of the useradd command, such as:
[root@localhost ~] # groupadd lamp1# add the lamp1 user group manually, because I will specify the initial welcome of the lamp1 user later. If it is not established in advance, it will report that the user group does not exist [root@localhost ~] # useradd-u 550-g lamp1-G root-d / home/lamp1-c "test user"-s / bin/bash lamp1# while establishing the user lamp1 Specified UID, initial group (lamp1), additional group (root), home directory (/ home/lamp1/), user description (test user) and user login Shell (/ bin/bash) [root@localhost ~] # grep "lamp1" / etc/passwd / etc/shadow / etc/group# to view the UID, initial group, user description of three files / etc/passwd:lamp1:x:550:502:test user:/home/lamp1:/bin/bash# users at the same time. The home directory and login Shell are consistent with the manual command / ETC _ etc/group:root:x:0:lamp1#lamp1 user has not set a password / the etc/group:root:x:0:lamp1#lamp1 user has joined the lamp1 group The root group is an additional group for lamp1 users / the group with an etc/group:lampl:x:502:#GID of 502 is the lamp1 group [root@localhost] # ll-d / home/lamp1/drwx- 3 lamp1 lamp1 4096 January 6 01:13 / home/lamp1/# home directory has also been established and does not need to be established manually
Through the above two ways, users can be created successfully. In general, there is no need to specify anything manually at all, because using default values can meet our requirements. Have you ever wondered where these default values of the useradd command are saved and whether they can be modified manually?
The answer is yes. The useradd command refers to two main default files when adding users, which are / etc/default/useradd and / etc/login.defs.
Thank you for reading this article carefully. I hope the article "how to increase users in linux" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.