Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Which is the add user command in linux

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article is about which user commands are added to linux. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

The linux add user command is useradd, which is first used to create a user account; then the password of the account is set with passwd and saved in the [/ etc/passwd] text file.

The linux add user command is useradd

1. Action

The useradd or adduser command is used to set up a user account and create a starting directory for the user, and the permission is superuser.

two。 Format

Useradd [- d home] [- s shell] [- c comment] [- m [- k template]] [- f inactive] [- e expire] [- p passwd] [- r] name

3. Main parameters

-c: add the comment text, which is saved in the remarks column of passwd.

-d: specify the home directory when the user logs in, replacing the system default / home/

-D: change the default value.

-e: specify the expiration date of the account, which is in the format of MM/DD/YY, such as 06max 30max 12. The default means permanent.

-f: specify how many days after the password expires to close the account. If the account is 0, it is disabled immediately; if it is-1, the account is always available. The default value is-1.

-g: specify the group to which the user belongs. Value can make the group name also be GID. The user group must already exist, and the period default is 100, that is, users.

-G: specifies the additional group to which the user belongs.

-m: automatically establish the login directory of the user.

-M: do not automatically create a user's login directory.

-n: cancels the establishment of a group with the user name.

-r: set up a system account.

-s: specifies the shell to be used by the user after logging in. The default is / bin/bash.

-u: specify the user ID number. This value must be unique in the system. 0room499 is reserved for system user accounts by default, so the value must be greater than 499.

4. Description

Useradd can be used to set up a user account, which is the same as the adduser command. After the account is set up, use passwd to set the password of the account. The account created with the useradd command is actually saved in the / etc/passwd text file.

5. Application example

Set up a new user account testuser1 and set UID to 544. The home directory is / usr/testuser1, which belongs to the users group:

# useradd-u 544-d / usr/testuser1-g users-m testuser1

Add-m to create automatically if the home directory does not exist

6. Example

Log in to the system using the administrator account to establish the user's tmp_3452 password 3sdt5:Eawhg

Add a user command:

[root@ptr228 ~] # adduser tmp_3452

Change password command:

[root@ptr228 ~] # passwd tmp_3452

Enter the password when prompted by the system: enter the password again after the 3sdt5:Eawhg system prompts you to enter the confirmation password. OK added successfully.

7.useradd add users in batch

When using useradd, if you do not add any parameter options later, for example: the user created by # sudo useradd test will be the default "three nots" user: one without Home Directory, two without password, and three without system Shell.

The steps are as follows:

(1) create a user name list file username.txt (ditto)

(2) create the file serc.txt corresponding to the user password in username:password format (pay attention to the format of the file)

Stu1:tt1stu2:tt2stu3:tt3stu4:tt4stu5:tt5stu6:tt6

(3) script file aa.sh added in batch

# # add users and generate user directories for users under / home/. Cat < username.txt | xargs-n 1 useradd-masks # update password in batch mode chpasswd < serc.txt## convert the above password to password file and group file pwconv## end verification information echo "OK New complete" (4) execute the script file and view the execution process root@liu:/home/liu/Desktop/Dos# sh aa.sh

When the new useradd command is completed, it will not output any information or interact with the user without error. But users must remember those settings, or the added users may have some unexpected results.

Thank you for reading! On the linux to add user commands which is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report