← 返回命令列表

Linux command

useradd 命令

安全

权限或系统影响较大,执行前请核对目标。

常用示例

Example

sudo useradd username

Example

sudo useradd -u 1001 username

Example

sudo useradd -s /bin/zsh username

Example

sudo useradd -G group1,group2 username

Example

sudo useradd -m username

Example

sudo useradd -k /etc/skel -m username

Example

sudo useradd -r username

说明

useradd is a low-level utility for adding users to the system. It updates system files and optionally creates home directories with initial files. On Debian-based systems, the higher-level adduser command is often preferred.

参数

-c, --comment COMMENT
Set user's full name or description (GECOS field)
-d, --home-dir HOME_DIR
Specify custom home directory path
-e, --expiredate DATE
Set account expiration date (YYYY-MM-DD)
-f, --inactive DAYS
Days after password expires until account is disabled
-g, --gid GROUP
Assign primary group
-G, --groups GROUP1,GROUP2
Add to supplementary groups
-k, --skel SKEL_DIR
Specify skeleton directory for home directory files
-m, --create-home
Create the user's home directory
-M, --no-create-home
Do not create home directory
-p, --password PASSWORD
Set encrypted password
-r, --system
Create a system account
-s, --shell SHELL
Set login shell
-u, --uid UID
Assign specific user ID
-U, --user-group
Create a group with same name as user
-N, --no-user-group
Do not create a matching group
-D
Display or modify default values

FAQ

What is the useradd command used for?

useradd is a low-level utility for adding users to the system. It updates system files and optionally creates home directories with initial files. On Debian-based systems, the higher-level adduser command is often preferred.

How do I run a basic useradd example?

Run `sudo useradd username` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -c, --comment COMMENT do in useradd?

Set user's full name or description (GECOS field)