groupdel删除nginx组时出现乐这个问题
【故障现象】用groupdel删除test组时,报以上错误。原因为nginx组中有nginx用户(nginx的主组)。
[root@c7-45 ~]# groupdel nginx
groupdel: cannot remove the primary group of user 'nginx'
【解决办法】先删除nginx用户
[root@c7-45 ~]# tail /etc/group
tss:x:59:
abrt:x:173:
sshd:x:74:
postdrop:x:90:
postfix:x:89:
ntp:x:38:
cgred:x:996:
docker:x:995:
deploy:x:1000:
nginx:x:1001:
[root@c7-45 ~]# userdel -r nginx
[root@c7-45 ~]# tail -n 2 /etc/group
docker:x:995:
deploy:x:1000:
[root@c7-45 ~]# getent group nginx
【注意事项】
-g与-G区别
-g, --gid GROUP force use GROUP as new primary group
-G, --groups GROUPS new list of supplementary GROUPS
-g是更改用户的主组
-G是将用户加到新的组里
usermod -g groupname username
usermod -G groupname username