linux命令之~groupadd

本文详细介绍了Linux系统管理命令groupadd的使用方法,包括其功能、语法、各选项的作用及使用场景,例如如何创建新的用户组、指定GID、处理GID重复情况等,并解释了与之相关的配置文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.一般man command的形式可以获得更详细的资料相比于command --help

2.man groupadd

[root@localhost ~]# man groupadd
GROUPADD(8)               System Management Commands               GROUPADD(8)

NAME
       groupadd - create a new group  #功能说明

SYNOPSIS
       groupadd [-g gid [-o]] [-r] [-f] [-K KEY=VALUE] group           #列出所有的选项

DESCRIPTION
       The groupadd command creates a new group account using the values specified on the command line and the default values from the system. The new group will be
       entered into the system files as needed.

OPTIONS
       The options which apply to the groupadd command are:

       -f This option causes to just exit with success status if the specified group already exists. With -g, if specified GID already exists, other (unique) GID is chosen
          (i.e.  -g is turned off).

 #强制创建,如果指定的参数-g出现重复情况,那么其它的gid将会被使用,如:

[root@localhost ~]# groupadd -g 3005 zbk62
groupadd: GID 3005 is not unique
[root@localhost ~]# groupadd  -f -g 3005 zbk62
[root@localhost ~]# id zbk62
uid=102(zbk62) gid=3006(k03) groups=3006(k03)   #虽然指定了3005但系统用了3006



       -r This flag instructs groupadd to add a system account.  The first available gid lower than 499 will be automatically selected unless the -g option is also given
          on the command line. This is an option added by Red Hat.


#添加系统帐户,如果没有指定-g的参数,那么它将自动选用小于499的GID数字;

       -g GID
          The numerical value of the group’s ID. This value must be unique, unless the -o option is used. The value must be non-negative. The default is to use the
          smallest ID value greater than 500 and greater than every other group. Values between 0 and 499 are typically reserved for system accounts.


#指定GID,如果没有-o选项那么它将是唯一的,默认值它是大于500以及其它组的最小值,0-499的值预留给系统帐户;


       -h, --help
          Display help message and exit.

       -K KEY=VALUE
          Overrides /etc/login.defs defaults (GID_MIN, GID_MAX and others). Multiple -K options can be specified.

#摆脱文件/etc/login.defs的值大小的限制,比如文件中指定GID_MIN为5000,那么你可以指定这个组的GID_MIN为6000,改变系统赋予的默认初值;

          Example: Set the gid of range from 100 to 499.

          # groupadd -K GID_MIN=100 -K GID_MAX=499 test

          The new group "test" is added into /etc/group.

           /etc/group test:x:105:

          Note: This option does not work when arguments are separated by comma.

          (Example: -K GID_MIN=10,GID_MAX=499)


       -o This option permits to add group with non-unique GID.


涉及到的相关文件:

FILES
       /etc/group
          Group account information.

       /etc/gshadow
          Secure group account information.

       /etc/login.defs
          Shadow password suite configuration.

CAVEATS #说明

       Groupnames must begin with a lower case letter or an underscore, and only lower case letters, underscores, dashes, and dollar signs may follow. In regular
       expression terms: [a-z_][a-z0-9_-]*[$]

       Groupnames may only be up to 16 characters long.

       If the groupname already exists in an external group database such as NIS, groupadd will deny the group creation request.

       Groupnames may only be up to 16 characters long.

#组名可以以_,字母开头,以$结尾,只要符合这个匹配模式:[a-z_][a-z0-9_-]*[$]

组名的长度为最长16个字符长。

而对于NIS:

通俗点说NIS服务器可用统一来管理机器和用户信息.
    相当于 不用在每台机器上分别设置  hosts和passwd 文件. 只在NIS Server端统一设置.
NIS客户端用nis相应命令和服务端绑定. 客户端hosts只要有自己和NIS Server的信息即可.


EXIT VALUES
       The groupadd command exits with the following values:

       0  success

       2  invalid command syntax

       3  invalid argument to option

       4  GID not unique (when -o not used)

       9  group name not unique

       10 can’t update group file

SEE ALSO
       chfn(1), chsh(1), passwd(1), gpasswd(8), groupdel(8), groupmod(8), login.defs(5), useradd(8), userdel(8), usermod(8).

System Management Commands        06/24/2006                       GROUPADD(8)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值