I am trying to delete a user named vivek using the userdel command as follows

userdel -r vivek
userdel: user vivek is currently used by process 749

How do I fix this problem and delete username vivek on a Debian Linux 9.x server?

One can use the userdel command to delete a user account on a Debian or any other Linux distro. It is a low level utility for removing users.
On Debian, sysadmin should usually use deluser command instead.

Understanding problem

It seems that PID # 749 used by a user named vivek. It can be simple open ssh session or something running in the background. Use the ps command to find out about a PID # 749:
$ ps aux | grep 749
Sample outputs:

vivek      749  0.0  0.1  92716  4028 ?        S    17:03   0:00 sshd: vivek@pts/0
root     10038  0.0  0.0  12784   944 pts/1    S+   17:13   0:00 grep 749

The ‘sshd: vivek@pts/0’ indicates that active ssh session. From the man page:

userdel will not allow you to remove an account if there are running processes which belong to this account. In that case, you may have to kill those processes or lock the user’s password or account and remove the account later. The -f option can force the deletion of this account.

So, all you have to do is kill this PID and run the userdel command again using either the kill command/killall command:
# kill -15 749
# killall -TERM -u vivek
Verify it:
$ ps aux | grep 749
Now delete the user account name vivek:
# userdel -r vivek
Verify that user account deleted from /etc/passwd and /etc/shadow file with the id command or grep command:
$ id vivek
$ grep ^vivek /etc/passwd
$ grep vivek /etc/shadow

Another option is to pass the -f option to the userdel command. This option forces the removal of the user account, even if the user is still logged in. It also forces userdel to remove the user’s home directory and mail spool, even if another user uses the same home directory or if the mail spool is not owned by the specified user. You must be very careful while using the -f option as it may leave your system in an inconsistent state:
# userdel -f userNameHere
See man pages for more info:
$ man userdel
$ man deluser
$ man 5 passwd
$ man 5 shadow

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • khan Dec 14, 2017 @ 1:44

    when i want to delete user in linux it tell me (user khan is currently used by process 1115 ) and does not delete .

    i used these command but still does not work
    1: userdel -r khan
    2: userdel -f khan
    but still show me same problems .

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum