Unable to remove user: "user is currently logged in"

Solution 1:

SU to the user su - username and run kill -9 -1 as the user.

Exit the shell and try the userdel -r username again.

Or you can check for processes from the user using lsof -u username and kill the relevant PIDs.

Or pkill -u username or pkill -u uid

Solution 2:

Or ps aux | grep <username> and kill the processes the user is running.


Solution 3:

If the above steps don't help! (Assuming you are using on the runlevel 5)

You could try the following:

  1. Change the runlevel to 3 (init 3)
  2. log-in with other than deleting account to delete (root/other account)
  3. userdel -r username