User and group operations are not done frequently and will be forgotten, so I will summarize them.
cat /etc/passwd
###Execution result############
user_name1:1001:1001::/home/user_name1:/bin/bash
user_name2:x:1002:1002::/home/user_name2:/bin/bash
useradd {user_name}
userdel {user_name}
cat /etc/group
###Execution result############
root:x:0:
~ ~ Omitted ~ ~
group_name1:x:1003:user_name1,user_name2
group_name2:x:1004:user_name1
groupadd {group_name}
groupdel {group_name}
getent group {group_name}
###Execution result############
group_name1:x:1003:user_name1,user_name2
groups {user_name}
#Execution result
user_name1 : user_name1 group_name1 group_name2
If you also want to know the UID and GID
id {user_name}
###Execution result############
uid=1001(user_name1) gid=1001(user_name1) groups=1001(user_name1),1003(group_name1),1004(group_name2)
gid=
... Primary group
groups =
... the first is the Primary group, the second is the Secondary group
usermod -g {group_name} {user_name}
※※Caution※※
The -G
option ** ignores and overwrites existing groups **.
If you want to add a group while keeping the existing group, you need to ** specify the existing group as well **.
You can check the existing group with ʻid {user_name} `.
usermod -G {group_name} {user_name}
To specify more than one, separate them with , (comma)
.
usermod -G {group_name1},{group_name2} {user_name}
Take advantage of the property of ** ignoring and overwriting ** existing groups of the -G
option.
Check the existing group with ʻid {user_name} `, and specify the group you want to delete.
usermod -G {group_name1},{group_name2} {user_name}
Recommended Posts