Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to delete a user logged into my ubuntu system. Let's call the user bob.

I'm running

sudo userdel -r bob

The response I get is

userdel: user bob is currently logged in

So I run

ps -u bob

To find his bash session to kill it. But I'm not seeing it - I'm looking for something like:

13205 pts/0    00:00:00 bash

(Which is my session) but I don't see another one:

What command can I run to find out what this user is logged in as?


Edit:

who bob 

gives no result (to stdout at least)

last bob

gives a result three days ago - but running

sudo userdel -r bob

Still gives the same result.


Edit

who

only gives my login.


Edit

root@machine:~# sudo userdel -rf bob
userdel: user bob is currently logged in
userdel: warning: can't remove /var/mail/bob: No such file or directory
userdel: error removing directory /
root@machine:~# sudo userdel -rf bob
userdel: user 'bob' does not exist

This seems like it was not a correct type of user - is that correct?

share|improve this question
    
What do last bob and who say? –  Dennis Williamson Feb 19 '11 at 15:49
add comment

5 Answers

up vote 1 down vote accepted

Does sudo userdel -rf bob work? If not, what error does it give?

share|improve this answer
    
Best answer so far... –  Hawkeye Feb 20 '11 at 1:43
add comment

track down the session off the user

ps -u | grep bob

and then kill them.

Or, i you are feeling confident:

kill -15 $(ps -U bob -o "pid=")

Otherwise, you could try forcing the userdel by adding the -f option.

share|improve this answer
add comment

quick and dirty

ps fuxaw |grep ^bob | awk '{print $2}' | xargs kill -9

this will kill all bobs processes, so you can proceed with deleting the account.

share|improve this answer
    
This gave an error saying kill didn't have proper arguments... output Usage: ... etc –  Hawkeye Feb 20 '11 at 0:55
    
that means that there were no processes of user bob to kill –  Hrvoje Špoljar Feb 20 '11 at 3:08
add comment

Run ps command:

ps auxwwwf | less

then press '/bob' and press enter(to search):

ooshro    4465  0.0  0.6 223480 19348 ?        Rl   Feb18   1:19 gnome-terminal
ooshro    4466  0.0  0.0  14488   792 ?        S    Feb18   0:00  \_ gnome-pty-helper
ooshro    4467  0.0  0.1  22116  4884 pts/1    Ss   Feb18   0:00  \_ bash

root      1208  0.0  0.0  71268  2040 tty2     Ss   Feb18   0:00 /bin/login --       
ooshro   18088 10.5  0.1  22176  4932 tty2     S+   17:40   0:00  \_ -bash

root       579  0.0  0.5   5632  2192 ?        Ss   09:17   0:00 /usr/sbin/sshd -D
root       706  0.0  0.7   8432  2784 ?        Ss   11:57   0:00  \_ sshd: ooshro [priv] 
ooshro     722  0.0  0.3   8564  1308 ?        S    11:57   0:02      \_ sshd: ooshro@pts/0  
ooshro     723  0.0  1.3   9808  5220 pts/0    Ss   11:57   0:00          \_ -bash
share|improve this answer
    
This only gives my processes, but sudo userdel -r bob still claims that they're logged in. –  Hawkeye Feb 20 '11 at 0:53
add comment

The who command should work.

Or you could display all processes belong to bob with ps -au bob.

share|improve this answer
    
who just displays my login. ps -au bob displays all running processes. –  Hawkeye Feb 20 '11 at 0:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.