(1) add a new group and delete
[root@localhost home]# groupadd -g 1001 Centos_User_Group1
[root@localhost home]# groupadd -g 1001 Centos_User_Group1
groupadd: group 'Centos_User_Group1' already exists
[root@localhost home]#
[root@localhost home]# groupdel Centos_User_Group1
[root@localhost home]# groupdel Centos_User_Group1
groupdel: group 'Centos_User_Group1' does not exist
##################################################
##################################################
(2) add a new user to exited group and delete
[root@localhost home]# useradd -u 1001 -g 1001 -d /home/Group1User1 Group1User1
[root@localhost home]# useradd -u 1001 -g 1001 -d /home/Group1User1 Group1User1
useradd: user 'Group1User1' already exists
[root@localhost home]#
[root@localhost home]# userdel -r Group1User1
[root@localhost home]# userdel -r Group1User1
userdel: user 'Group1User1' does not exist
##################################################
useradd -u 1002 -g 1001 -d /home/Group1User2 Group1User2
useradd -u 1003 -g 1001 -d /home/Group1User3 Group1User3
##################################################
##################################################
(3) add a new user and delete
[root@localhost home]# adduser -u 1004 User4ToGroup1
[root@localhost home]# adduser -u 1004 User4ToGroup1
adduser: user 'User4ToGroup1' already exists
[root@localhost home]#
[root@localhost home]# userdel -r User4ToGroup1
[root@localhost home]# userdel -r User4ToGroup1
userdel: user 'User4ToGroup1' does not exist
##################################################
##################################################
(4) create a new user,
move it to a exited group,
delete the dafault group it belongs to
(this command will automatically create a new group with group name same as user name)
[root@localhost zlf]# adduser -u 1004 User4ToGroup1
[root@localhost zlf]# su User4ToGroup1
[User4ToGroup1@localhost zlf]$ id
uid=1004(User4ToGroup1) gid=1004(User4ToGroup1) groups=1004(User4ToGroup1) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[User4ToGroup1@localhost zlf]$
(now, we move user User4ToGroup1 to a exited group Centos_User_Group1)
[User4ToGroup1@localhost zlf]$ su
Password:
[root@localhost zlf]# usermod -g 1001 -d /home/User4ToGroup1 User4ToGroup1
[root@localhost zlf]# su User4ToGroup1
[User4ToGroup1@localhost zlf]$ id
uid=1004(User4ToGroup1) gid=1001(Centos_User_Group1) groups=1001(Centos_User_Group1) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[User4ToGroup1@localhost zlf]$
[User4ToGroup1@localhost zlf]$ su
Password:
[root@localhost zlf]# groupdel User4ToGroup1
[root@localhost zlf]# groupdel User4ToGroup1
groupdel: group 'User4ToGroup1' does not exist
[root@localhost zlf]#
##################################################
##################################################
(5) create a new user and add it to a exited group when creating
useradd -g Centos_User_Group1 UserInGroup
##################################################
##################################################
(6) check users and groups
whoami
id
groups
groups username
vi /etc/group
vi /etc/passwd
##################################################
[root@localhost zlf]# whoami
root
[root@localhost zlf]# id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@localhost zlf]#
[root@localhost zlf]#
[root@localhost zlf]#
[root@localhost zlf]#
[root@localhost zlf]# whoami
root
[root@localhost zlf]#
[root@localhost zlf]# id
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@localhost zlf]#
[root@localhost zlf]# groups
root
[root@localhost zlf]#
[root@localhost zlf]# groups UserInGroup
UserInGroup : Centos_User_Group1
[root@localhost zlf]#
[root@localhost zlf]# vi /etc/group
[root@localhost zlf]#
[root@localhost zlf]# vi /etc/passwd
##################################################
[root@localhost zlf]# su UserInGroup
[UserInGroup@localhost zlf]$
[UserInGroup@localhost zlf]$ whoami
UserInGroup
[UserInGroup@localhost zlf]$
[UserInGroup@localhost zlf]$ id
uid=1005(UserInGroup) gid=1001(Centos_User_Group1) groups=1001(Centos_User_Group1) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[UserInGroup@localhost zlf]$
[UserInGroup@localhost zlf]$ groups
Centos_User_Group1
[UserInGroup@localhost zlf]$
[UserInGroup@localhost zlf]$ groups root
root : root
[UserInGroup@localhost zlf]$
[UserInGroup@localhost zlf]$ vi /etc/group
[UserInGroup@localhost zlf]$
[UserInGroup@localhost zlf]$ vi /etc/passwd
[root@localhost zlf]# vi /etc/group
[root@localhost zlf]# vi /etc/passwd
[UserInGroup@localhost zlf]$ vi /etc/group
[UserInGroup@localhost zlf]$ vi /etc/passwd