linux中groupadd、groupmod、groupdel、newgrp命令

groupadd命令
功能:添加用户组
用法:groupadd [-g gid][-o][-r][-f] groupname
参数
-g gid:除非使用-o参数不然该值必须是唯一,不可相同。数值不可为负。
-o:允许设置相同组id的群组
-r:建立系统组
-f:强制执行,默认是不允许创建相同id的组的,使用此参数就可以,而且不用-o选项。

groupmod命令
功能:修改用户组
用法:groupmod [-g gid [-o]] [-n group_name] group
参数:
-g gid:指定id
-o:与groupadd相同
-n group_name:修改用户组名为group_name

groupdel命令
功能:删除用户组
用法: groupdel group
参数:无
说明:删除用户组时,用户组必须存在,如果有组中的任一用户在使用中的话,则不能删除。

 

 

newgrp 是切换当前有效组的命令,你只能在你用户所属的组中切换

[root@centos ~]# useradd test1
[root@centos ~]# useradd test2
[root@centos ~]# usermod -G test2 test1
[root@centos ~]# usermod -G test1 test2

[root@centos ~]# su - test1
[test1@centos ~]$ id
uid=500(test1) gid=500(test1) groups=500(test1),501(test2)
[test1@centos ~]$ newgrp test2
[test1@centos ~]$ id
uid=500(test1) gid=501(test2) groups=500(test1),501(test2)

[test2@centos ~]$ exit
[test2@centos ~]$ exit

[root@centos ~]# su - test2
[test2@centos ~]$ id
uid=501(test2) gid=501(test2) groups=500(test1),501(test2)
[test2@centos ~]$ newgrp test1
[test2@centos ~]$ id
uid=501(test2) gid=500(test1) groups=500(test1),501(test2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值