Howto: Linux Kill and Logout Users

by on August 14, 2006 · 32 comments· LAST UPDATED March 9, 2011

in , ,

Yet another newbie question that suggests people love to kill and show their power to rest of the world ;)

There is a package called procps. It includes various useful (nifty) utilities. One of such utility is skill which is responsible to send a signal to users and process such as:

  • Halt user terminal
  • Kill user and logout


The procps package contains utilities to browse the /proc filesystem, which is not a real file system but a way for the kernel to provide information about the status of entries in its process table. Procps includes ps, free, skill, pkill, pgrep, snice, tload, top, uptime, vmstat, w, watch and pdwx commands.

Task: How To Halt/Stop a User Called vivek

Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following commands. First, switch to the root user by typing su - and entering the root password, when prompted (you can also use sudo if configured). Type the skill command as follows:
# skill -STOP -u vivek
The skill command sends a terminate command (or another specified signal) to a specified set of processes.

Task: Resume Halted User Called vivek

Send CONT single to user vivek, type the following command:
# skill -CONT -u vivek

Task: Kill and Logout a User Called vivek

You can send KILL single, type the following command:
# skill -KILL -u vivek

Task: Kill and Logout All Users

The ultimate command to kill and logout all users is as follows:
# skill -KILL -v /dev/pts/*

WARNING! These tools are obsolete, unportable and it is here due to historical reasons. Consider using the killall, pkill, and pgrep commands instead as follows.

pkill command

To halt or stop a user called vivek, enter:
# pkill -STOP -u vivek
To resume a user called vivek, enter:
# pkill -CONT -u vivek
To kill all php-cgi process owned by vivek user, enter:
# pkill -KILL -u vivek php-cgi

Other useful nifty utilities provided by procps package

  • w command : Show who is logged on and what they are doing.
  • kill command : Send signal to a process (explains how to kill process under Linux)
  • top command : Display Linux tasks and other important stuff
  • vmstat command : Display virtual memory statistics.
  • free command : Display free and used memory (RAM) statistics.
  • slabtop command : Display kernel slab cache information in real time.
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 32 comments… read them below or add one }

1 max August 15, 2006 at 8:48 am

This stuff is very cool!
I manage an iternet cafe linux-based and to log-out users remotely since now I first logged in the client machine via ssh and then export DISPLAY=:0 and kdeinit_shutdown.But doing that I was lucky with kde as default wm, while ‘skill -KILL -u user’ is a better one_line command solution and for (I guess) all windows managers.
What I’m still wondering is: how to login remotely a user assuming that the default login manager is kdm?
Thanks in advance for any hint.

Reply

2 nixCraft August 15, 2006 at 9:39 am

Hey max,

Great to know you are using Linux for your internet cafe.

skill should works with an wm or shell as it directly sends a signal to user.

>What I\’m still wondering is: how to login remotely a user assuming that the default login manager is kdm?

Sorry but I am not getting your question. Can you explain it little more?

Reply

3 Ammar Shaikh January 11, 2012 at 7:56 am

Hello;

I m also not getting your question so please explain it briefly or understandable that is very helpful to you and all also…

Reply

4 max August 15, 2006 at 12:01 pm

>Sorry but I am not getting your question. Can you explain it little more?
Well, when a customer finish his session is comfortable for me remotely close the session, but when I need to start a new one I need to sit-up from my chair and then go to the client and put the passwd (the user account is setted as default in kdm config) manually in the kdm welcome_login_window.
Now I’m just wondering how to put remotely the passwd in kdm to open the session again without (being lazy :-]) uprise from my chair?
I hope this wouldn’t be a too much tricky question an sorry about my english that isn’t my first language @^_^@

Reply

5 nixCraft August 15, 2006 at 7:03 pm

Now, I understand your problem, you do not want go to each PC everytime new customer arrives. You can kill your customers session with skill but now you want to do auto login right from your own admin PC

Well I do not have exact solution but you can use KDE auto login facility to login the user automatically…

On the other hand, you may be writing some script, which will log them automatically

Another solution is kill user using skill
When new person comes for browsing just tell him to seat in front of computer
You login from your own admin pc to remote linux desktop system over ssh
And you type the command startx&
It will start the session on remove computer
In order to work this all system must boot to text mode
SSH should be running on all system
And autologin must be turned on for all linux system

Hope this helps

Reply

6 deivs January 22, 2007 at 10:30 am

how to logout specified user after one hour automatically,how to do ?

Reply

7 nixCraft January 22, 2007 at 3:11 pm

deivs.

You need to write a script. There is no inbuilt facility available, AFAK

Reply

8 Paul May 15, 2007 at 7:54 pm

Hi,

I was pleased to see the skill inf have ld sessins n an LTSP server. I have since set a timeout uing TMOUT=7200 in /etc/profile.
Iuse skill -KILL -u paul to try and remove the old sessions. It succesfully removed one but doesn’t seem to remove the other 2 that are reported by ‘who’. Is it possible that ‘who’ is reprting stale/non-existant sessions?

Reply

9 nixCraft May 16, 2007 at 9:46 am

Try to use pkill command
pkill -KILL -u username

Reply

10 Chris July 15, 2010 at 11:54 pm

According to the documentation, skill is obsolete and we should all be using pkill instead — see http://linux.die.net/man/1/skill

Reply

11 Masood Yarmohammadi May 27, 2007 at 3:39 pm

Hello,
i use
skill -KILL -u didi root

Now, i can’t login to ssh!

Reply

12 Waqar June 13, 2011 at 6:52 am

That’s Because u also killed “SSH”, u need to login via console and restart SSH Services.

Reply

13 Hong@macau July 18, 2007 at 9:34 am

i think when i enter this command
skill -KILL -u root

this will be kill all the process that create by root. such as ssh telnet process.

Reply

14 deivs September 16, 2007 at 9:38 am

script to logout the users in the specific time

Reply

15 De.. December 7, 2007 at 9:09 pm

i want to delete the process because my systems average load is too high 150.0 and more some time
and when i delete them ..they goes to and start increasing the load continously..
the process are perl scripts..
please help urgent

Reply

16 De.. December 7, 2007 at 9:11 pm

the process hang up and when i shen them it shows like “defunction”

Reply

17 Terry January 8, 2008 at 9:05 pm

Oops didn’t read through all the threads. I had a user who was logged on remotely as root but when I ran the command we were kicked out of our SSH sessions
Is there any way to recover SSH functionality short of rebooting

Reply

18 Anonymous September 5, 2008 at 4:00 am

Only if you have another way of logging in (e.g. telnet, vnc, etc)

Reply

19 Afrizal October 11, 2008 at 4:16 pm

Thank you for your shared knowledge.

Great info.

thanks,

zall

Reply

20 lee o November 9, 2008 at 6:01 pm

Something for Linux Monty Python fans – one of you show a more funny way of kicking users off a linux box than THIS ONE HERE.. Very entertaining!

Reply

21 viper December 6, 2008 at 7:46 am

how about to remove halt application..
at the bios I can’t find to solve that..
thanx…

Reply

22 kaminisuresh February 26, 2010 at 11:05 am

hi
this is suresh i want which pc is having some server,how to identify which is having server

Reply

23 bishnoink September 15, 2010 at 5:01 am

I have tried “skill -KILL /dev/pts/*” its not working on rhel5.

alternative to kill all users sessions except “root” is:

who -w|awk ‘{print $1}’|grep -v root|xargs skill -KILL -u
*don’t forget to use “grep -v root” otherwise this will kill all the processes.

Thanks

Reply

24 Bilal Bhat November 28, 2010 at 7:27 am

Brilliant bishnoink, you made my life easy… Thanks for sharing the command…

Reply

25 Mish March 9, 2011 at 1:12 pm

I wanna know, how to block the users being ruining programs in bios level.
this is like blocking websites for various users in bios level.

ex; user “A” logging and browse internet (www.google.com)
after user “B” logging and browse the internet BUT HE CANT GO TO “www.google.com” from any browser.

If you all have a suggestions how to block this kind of a session, I would be much appreciated.

Tx

Reply

26 Vishnu Ram May 26, 2011 at 9:04 am

Hello,

I need to kill an user session which is not being used by that particular user for last 10 days. Please help me to get a script for that.

Reply

27 Naresh Kumar May 26, 2011 at 12:19 pm

@ Vishnu,

You can use following command.
who -w|awk ‘{print $1}’|grep username|xargs skill -KILL -u

Reply

28 Mehdi September 8, 2011 at 2:22 pm

Hi,

If all the sessions have been made by a user, i.e. vivek, is it possible to kill a session based on TTY?

Reply

29 Daniel Vieceli March 13, 2012 at 2:06 am

Thanks, very good.

Reply

30 PVIBES March 7, 2013 at 8:37 pm

I found this guys.
Just replace USERNAME with the desired user session to be killed.

kill -1 `ps ax | grep -i USERNAME | grep -i priv | cut -d ” ” -f 1`

Reply

31 cilgin_dj_hore April 28, 2014 at 4:01 pm

aq ibneleri hey dude this fucking code skill -STOP -u root fucked my machine . i di o T

Reply

32 chika August 29, 2014 at 7:34 am

pkill -9 -u ardi

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , , , , , , , ,

Previous post:

Next post: