Linux基础命令[25]-groupadd

1. groupadd 命令说明

groupadd:用于创建用户组,基本信息如下:

Usage: groupadd [options] GROUP

Options:
  -f, --force                   exit successfully if the group already exists,
                                and cancel -g if the GID is already used
  -g, --gid GID                 use GID for the new group
  -h, --help                    display this help message and exit
  -K, --key KEY=VALUE           override /etc/login.defs defaults
  -o, --non-unique              allow to create groups with duplicate
                                (non-unique) GID
  -p, --password PASSWORD       use this encrypted password for the new group
  -r, --system                  create a system account
  -R, --root CHROOT_DIR         directory to chroot into
  -P, --prefix PREFIX_DIR       directory prefix

基本参数如下:

选项作用
-f, --force强制创建新用户组
-g, --gid GID指定新用户组的组ID
-h显示帮助信息并退出
-K, --key KEY=VALUE覆盖/etc/login.defs 中的默认值
-o, --non-unique允许创建有重复 GID 的用户组
-p, --password PASSWORD为新用户组使用加密过的密码
-r, --system创建一个系统账户
-R, --root CHROOT_DIRchroot 到的目录
-P, --prefix PREFIX_DIR指定新创建的用户组的父用户组

2. groupadd 命令语法

groupadd [options] GROUP

3. groupadd 命令示例

3.1 不加参数

不加参数时,直接创建用户组,组ID默认新增1,若用户组已存在,会有报错。

/etc/group 保存有组信息。

[root@localhost ~]# tail -5 /etc/group
tuser3:x:1007:
tuser13:x:981:
demo1:x:1008:
demo2:x:1010:
tuser15:x:1011:
[root@localhost ~]# groupadd tuser16
[root@localhost ~]# tail -5 /etc/group
tuser13:x:981:
demo1:x:1008:
demo2:x:1010:
tuser15:x:1011:
tuser16:x:1012:
[root@localhost ~]# groupadd tuser16
groupadd: group 'tuser16' already exists
[root@localhost ~]# 

在这里插入图片描述

3.2 -f(强制创建)

-f 可以强制创建用户组,一般用于脚本。

[root@localhost ~]# groupadd -f tuser16
[root@localhost ~]# tail -5 /etc/group
tuser13:x:981:
demo1:x:1008:
demo2:x:1010:
tuser15:x:1011:
tuser16:x:1012:
[root@localhost ~]# 

在这里插入图片描述

3.3 -g(指定组ID)

组ID必须是一个正整数,且唯一。默认是上个组ID自增1,-g 可以指定新用户组的组ID。

[root@localhost ~]# groupadd -g 11020 tuser17
[root@localhost ~]# tail -5 /etc/group
demo1:x:1008:
demo2:x:1010:
tuser15:x:1011:
tuser16:x:1012:
tuser17:x:11020:
[root@localhost ~]# 

在这里插入图片描述

3.4 -r(系统用户组)

系统用户组的组ID通常是小于1000的值,并且不会显示在登录界面的用户列表中。这些组通常用于系统服务和进程。

[root@localhost ~]# groupadd -r sysgrp
[root@localhost ~]# tail -5 /etc/group
tuser15:x:1011:
tuser16:x:1012:
tuser17:x:11020:
test16:x:11021:
sysgrp:x:980:
[root@localhost ~]# 

在这里插入图片描述

4. 总结

groupadd 用于创建自定义用户组,并可以改变其部分属性。

  • 10
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值