22

When trying to remove the user, it returns "user is currently logged in".
I already killed the user using pkill -KILL -u usernameHere and several other commands, but it does not help.

How can I remove this user?

Running CentOS 6.

Xen
  • 461
  • 1
  • 4
  • 16

4 Answers4

50

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

ewwhite
  • 194,921
  • 91
  • 434
  • 799
  • 1
    Be careful! Using the first command above killed all my userpace daemons. Since it is a production server I had to restart them all manually. So it's kind of a dangerous command on a production server. In my case it was a node hosting dozens of VPS servers so it was a major thing for me. – Fred Flint Feb 20 '18 at 18:30
8

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

Sirch
  • 5,697
  • 4
  • 19
  • 36
  • 1
    This was the first thing I tried before Googling this. When I did it, I got nothing in the grep results. – Vic Aug 08 '14 at 21:25
2

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
MohanBabu
  • 121
  • 2
-2

I try the steps to del the user1

  1. su user1

  2. kill -9 -1

  3. su

  4. sudo deluser user1

  • I don't see anything new in this answer. And the older answers have better explanations of what they are doing. – kasperd Apr 04 '16 at 12:53