Troubleshoot issues where Linux cannot use Userdel to delete users and groups
- System environment
#cat /etc/redhat-releaseCentOS release 6.7 (Final)#getenforceDisabled
- Problem description
我在root账户下,删除普通账户worker时,出现如下报错信息:#userdel -r workeruserdel: user worker is currently used by process 1973 我把1973这个进程kill了,再次使用userdel -r worker命令#userdel -r workeruserdel: user worker is currently used by process 1986也就是没有真正的kill掉
- Cause of the problem
There are multiple services running on the worker account, some of which may be in use by root, and we can see the PID number under the user by Ps-u Worker|awk ' {print $} '.
- Workaround
(1)查看该用户的pid#ps -u worker|awk ‘{print $1}‘26778267542673526736(2)编写脚本说明:如果该用户下的pid很多,如我这次遇到了7千多个,一个一个kill是很耗费时间的,也很无聊。脚本形式如下:#ps -u worker|awk ‘{print $1}‘ > 1.txt#cat rm.sh#!/bin/bashfor i in $(cat 1.txt)do kill -9 $idoneecho "ok"执行脚本:#sh rm.sh
- Command VIPW
(1)#vipw –help用法:vipw [选项]选项:-g, –group 编辑 group 数据库 -h, –help 显示此帮助信息并推出 -p, –passwd 编辑 passwd 数据库 -q, –quiet 安静模式 -R, –root CHROOT_DIR chroot 到的目录 -s, –shadow 编辑 shadow 或 gshadow 数据库(2)使用vipw原因保证数据的一致性,不然可能会造成系统崩溃或者一些莫名其妙的问题。(3)具体操作#vipw找到你用户worker,用dd删除那行(记得保存:wq or :x)。。之后。#vipw -s找到用户worker所属组,用dd删除即可(记得保存:wq or :x)(4)检查worker是否还存在#grep worker /etc/passwd
Troubleshoot issues where Linux cannot use Userdel to delete users and groups