linux 7.0删除用户,Centos7查看、创建、删除用户和组

(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

bd7a7dd0322673a3251fb13b5f600e83.png

[root@localhost zlf]# vi /etc/passwd

38695bac15348b0708100baf0f58e06c.png

[UserInGroup@localhost zlf]$ vi /etc/group

ba486bdc02d678a15ad40780d3b2fc9e.png

[UserInGroup@localhost zlf]$ vi /etc/passwd

6f1c973331534a0eb65f92bc21b3b194.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值