← 返回命令列表

Linux command

groupadd 命令

安全

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

常用示例

Example

sudo groupadd group_name

Example

sudo groupadd -r group_name

Example

sudo groupadd -g 1001 group_name

Example

sudo groupadd -U user1,user2 group_name

说明

groupadd creates a new group account on the system. It records the new group information in system files (/etc/group and /etc/gshadow), assigning a unique GID unless specified. System groups (created with -r) use GIDs from the system range defined in /etc/login.defs, typically below 1000.

参数

-f, --force
Exit successfully if group exists; use next available GID if specified one is taken
-g, --gid GID
Set numerical group ID (must be unique unless -o used)
-K, --key KEY=VALUE
Override /etc/login.defs defaults
-o, --non-unique
Allow creation with duplicate GID
-p, --password PASSWORD
Set encrypted group password
-r, --system
Create a system group
-U, --users USER1,USER2
Add users as group members
-R, --root CHROOT_DIR
Apply changes in chroot environment
-P, --prefix PREFIX_DIR
Apply changes in prefix directory
-h, --help
Display help message and exit

FAQ

What is the groupadd command used for?

groupadd creates a new group account on the system. It records the new group information in system files (/etc/group and /etc/gshadow), assigning a unique GID unless specified. System groups (created with -r) use GIDs from the system range defined in /etc/login.defs, typically below 1000.

How do I run a basic groupadd example?

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

What does -f, --force do in groupadd?

Exit successfully if group exists; use next available GID if specified one is taken