14

Is there a simple way for me to force another user off of a linux box, while I am logged in as root? I understand that I could determine what type of session they have open, and kill the pid - but I'm thinking there must be a command to do this that I don't know about.

Any ideas?

Brent
  • 22,219
  • 19
  • 68
  • 102

4 Answers4

15

You can simply slay(1) him. :-)

aronisstav
  • 103
  • 4
David Schmitt
  • 2,165
  • 2
  • 15
  • 25
10

You can kill all of an user's processes via skill. Example:

  • skill -TERM -u username

will send SIGTERM to all of username's processes. To kill them for good (via SIGKILL) use -KILL instead of -TERM - please note, though, that you will most likely cause them to lose data that way. It's highly effective, mind you...

skill is part of the procps package which is installed by all distributions by default.

Mihai Limbăşan
  • 3,071
  • 22
  • 19
  • For others that want to do this for all remote user session, the -v flag (`-v pts/*`), which is from the man page might be useful. – David Feb 27 '13 at 09:14
3

The pkill and killall are preferred over skill. This is from the skill man page:

These tools are probably obsolete and unportable. The command syntax is poorly defined. Consider using the killall, pkill, and pgrep commands instead.

This should do the trick:

sudo pkill -KILL -u [user]

or

sudo killall -u [user]
David
  • 356
  • 1
  • 3
  • 8
0

Another easy way to do it is to run kill -1 <pid> where pid is the process ID number of the SSH session.

By running this command, you can see all the sshd process trees, by killing the parent process ID you will effectively kill the user session associated with it:

$ ptree -p

Look for sshd and then run:

$ kill -1 39383

Where 39383 is an example of an arbitrary process ID number.

Yes Barry
  • 170
  • 1
  • 16