Home  >  Article  >  Operation and Maintenance  >  What is the command to add a new user in Linux?

What is the command to add a new user in Linux?

青灯夜游
青灯夜游Original
2023-02-08 12:08:3620155browse

The command to add a new user in Linux is "useradd". The useradd command is used to create a new user. The account created is saved in the "/etc/passwd" text file; the creation syntax is "useradd [option] username". If there are no special requirements, there is no need to use any options. User created successfully.

What is the command to add a new user in Linux?

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

In Linux systems, you can use the useradd command to create a new user.

What is the command to add a new user in Linux?

You can use the useradd command to create a new user. After the account is created, use the passwd command to set the account. password. Use userdel to delete the account. In fact, the account created using the useradd command is saved in the /etc/passwd text file.

useradd syntax

The syntax of this command is:

useradd [选项] 用户名

The options supported by this command are:

##-f Specify the number of days after the password expires to close the account-g Specify the group to which the user belongs-G Specify additional groups to which the user belongs-mAutomatically create the user's home directory-nCancel the creation of a group named after the user name- rCreate a system account##-s -u
Option Description
-c Add the remark text, remark The text will be saved in the comment field of the passwd file
-d Specify the user’s home directory
-e Specify the validity period of the account
Specify the shell used by the user to log in
Specify user id
## Create a new user using

##【★★★★★】

The basic format for creating a new user:
# 语法
useradd 用户名

# 示例
useradd zhangsan

After the creation is successful, you can see the newly created user account information at the end of the

/etc/passwdWhat is the command to add a new user in Linux? file:

But the user still has There is no login password set, and there is a directory named

zhangsanWhat is the command to add a new user in Linux? under the

/home/

directory, which is the user's home directory. When adding a new user, specify the corresponding user group【★★★★★】

We can specify the user group when creating a user, that is, the user Which group it belongs to. The syntax is as follows:
# 语法
useradd -g 用户组名 用户名

# 示例,将 wangwu 用户添加到 root 用户组中
useradd -g root wangwu

Note: The user group must exist. If it does not exist, an error message will be reported. What is the command to add a new user in Linux?

What is the command to add a new user in Linux?Specify the home directory for new users【★★★★★】

While creating new users , specify a home directory for it. The default is to create a directory with the same name as the user in the /home/ directory. But adding the

-d

option can specify other directories as the user's home directory. The syntax is as follows: <pre class="brush:js;toolbar:false;"># 语法 useradd -d 指定家目录 用户名 # 例如,创建 wuqi 用户时指定家目录为 /wuqi/useradd -d /wuqi/ wuqi</pre>##Related recommendations: "

Linux Video Tutorial

"What is the command to add a new user in Linux?

The above is the detailed content of What is the command to add a new user in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is SELinuxNext article:What is SELinux