Get the App
SLTechnology News&Howtos  ›  Servers  › 

Detailed explanation of the use of useradd Command in linux

Shulou Source: shulou.com Published: 2022-06-03 06:45:46 09月26日 Update

Today, what the editor shares with you is the detailed explanation of the use of the useradd command in linux. I believe many people do not know much about it. In order to make you better understand the detailed explanation of the use of the useradd command in linux, I have summarized the following contents for you. Let's look down together. I'm sure you'll get something.

Detailed explanation of useradd command

1. Action

The useradd command is used to set up a user account and create a starting directory for the user, with the permission of the root user.

Recommended: Linux video tutorial

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 starting directory when the user logs in.

-D: change the default value.

-e: specifies the validity period of the account, which is permanent by default.

-f: specify how many days after the password expires to close the account.

-g: specify the starting group to which the user belongs.

-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.

-u: specify the user ID number.

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 and set up ID:

# useradd david-u 544

It should be noted that the ID value should be greater than 500 as far as possible to avoid conflict. Because some special users will be established after Linux installation, values between 0 and 499 are generally reserved for system accounts such as bin and mail.

# useradd oracle-g oinstall-G dba

Create a new oracle user, which initially belongs to the oinstall group, and also makes him belong to the dba group.

# useradd tomcat-d / var/servlet/service-s / sbin/nologin

Cannot use shell, and its user directory is to / var/servlet/service

This is the end of the detailed explanation of the use of the useradd command in linux. I hope the above content can be of certain reference value to everyone and can be put into practice. If you like this article, you might as well share it for more people to see.

Tags: User account command directory remarks valid content password ownership text system start same learning for application between value function parameters at the same time remarks bar Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB NVidia Redmi Shulou Information