4.3- 删除用户 userdel详解

使用userdel命令将用户从系统中删除。
默认情况下,userdel只删除/etc/passwd文件中的用户信息,它不会删除账户在系统中的任何文件。

使用-r参数,userdel将删除用户的HOME目录和用户的邮件目录。

1、userdel -r 用户名,删除用户
删除/etc/passwd 用户 dafu1
删除/etc/shadow 用户 dafu1
删除/etc/group 用户 dafu1
删除/etc/gshadow 用户 dafu1
删除用户家目录
注意:针对用户组和附加组同于用户名的情况

[root@hadoop etc]# id dafu1
uid=1000(dafu1) gid=1000(dafu1) 组=1000(dafu1)
[root@hadoop etc]# cat /etc/passwd | grep dafu1
dafu1:x:1000:1000::/home/dafu1:/bin/bash
[root@hadoop etc]# cat /etc/shadow | grep dafu1
dafu1:!!:18132:0:99999:7:::
[root@hadoop etc]# cat /etc/group | grep dafu1
dafu1:x:1000:
[root@hadoop etc]# cat /etc/gshadow | grep dafu1
dafu1:!::
[root@hadoop etc]# ll /home/dafu1
总用量 0
[root@hadoop etc]# ls -lia /home/dafu1
总用量 12
51253822 drwx------. 3 dafu1 dafu1  78 8月  24 15:46 .
33586818 drwxr-xr-x. 7 root  root   76 8月  24 18:59 ..
51253823 -rw-r--r--. 1 dafu1 dafu1  18 10月 31 2018 .bash_logout
51265249 -rw-r--r--. 1 dafu1 dafu1 193 10月 31 2018 .bash_profile
51265250 -rw-r--r--. 1 dafu1 dafu1 231 10月 31 2018 .bashrc
 2099888 drwxr-xr-x. 4 dafu1 dafu1  39 6月  11 13:23 .mozilla
[root@hadoop etc]# userdel -r dafu1
[root@hadoop etc]# cat /etc/passwd | grep dafu1
[root@hadoop etc]# cat /etc/shadow | grep dafu1
[root@hadoop etc]# cat /etc/group | grep dafu1
[root@hadoop etc]# cat /etc/gshadow | grep dafu1
[root@hadoop etc]# ls -lia /home/dafu1
ls: 无法访问/home/dafu1: 没有那个文件或目录

2、userdel 用户名,删除用户
删除/etc/passwd 用户 dafu1
删除/etc/shadow 用户 dafu1
/etc/group 用户组依然存在
/etc/gshadow 用户组依然存在
注意:针对用户组和附加组不同于用户名的情况

[root@hadoop etc]# id dafu4
uid=1102(dafu4) gid=1100(dafu2) 组=1100(dafu2)
[root@hadoop etc]# cat /etc/passwd | grep dafu4
dafu4:x:1102:1100::/home/dafu4:/bin/bash
[root@hadoop etc]# cat /etc/shadow | grep dafu4
dafu4:!!:18132:0:99999:7:::
[root@hadoop etc]# cat /etc/group | grep dafu4
dafu2:x:1100:dafu4
[root@hadoop etc]# cat /etc/gshadow | grep dafu4
dafu2:!::dafu4
[root@hadoop etc]# ls -lia /home/dafu4
总用量 12
51265282 drwx------. 3 dafu4 dafu2  78 8月  24 18:59 .
33586818 drwxr-xr-x. 6 root  root   63 8月  24 19:13 ..
51265284 -rw-r--r--. 1 dafu4 dafu2  18 10月 31 2018 .bash_logout
51265285 -rw-r--r--. 1 dafu4 dafu2 193 10月 31 2018 .bash_profile
51265286 -rw-r--r--. 1 dafu4 dafu2 231 10月 31 2018 .bashrc
 2099892 drwxr-xr-x. 4 dafu4 dafu2  39 6月  11 13:23 .mozilla
[root@hadoop etc]# userdel dafu4
[root@hadoop etc]# cat /etc/passwd | grep dafu4
[root@hadoop etc]# cat /etc/shadow | grep dafu4
[root@hadoop etc]# cat /etc/group | grep dafu4
[root@hadoop etc]# cat /etc/group | grep dafu2
dafu2:x:1100:
[root@hadoop etc]# cat /etc/gshadow | grep dafu4
[root@hadoop etc]# cat /etc/gshadow | grep dafu2
dafu2:!::
[root@hadoop etc]# ls -lia /home/dafu4
总用量 12
51265282 drwx------. 3 1102 dafu2  78 8月  24 18:59 .
33586818 drwxr-xr-x. 6 root root   63 8月  24 19:13 ..
51265284 -rw-r--r--. 1 1102 dafu2  18 10月 31 2018 .bash_logout
51265285 -rw-r--r--. 1 1102 dafu2 193 10月 31 2018 .bash_profile
51265286 -rw-r--r--. 1 1102 dafu2 231 10月 31 2018 .bashrc
 2099892 drwxr-xr-x. 4 1102 dafu2  39 6月  11 13:23 .mozilla
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值