125

Sometimes when there are too many users logged in it can cause my computer to become very slow and laggy due to low amount of available RAM. I would like to be able to quickly log out the other users from the command line instead of manually switching into each user and logging them out.

Is this possible?

muru
  • 207,228
Isaiah
  • 60,750

3 Answers3

130

this is one answer

who -u

that give you the PID

Then you can kill the user session.

kill "pid"
David Foerster
  • 36,890
  • 56
  • 97
  • 151
hhlp
  • 42,872
55

You may use who to check which users are logged in:

who

You can log-out the user by sending the KILL signal to the user-process with:

sudo pkill -KILL -u <username>

(which is same as sudo pkill -9 -u <username>)

example:

sudo pkill -9 -u guest-2Rw4Lq

(to kill a guest session user named guest-2Rw4Lq)

Note (kudos to pbhj): If you get locked in a console, use Ctrl+Alt+F7 to get back to the GUI.

Lorenz Keel
  • 9,511
rusty
  • 16,917
10
who -u


> adam     ttys000  Aug  4 09:22   .       91228 

then

sudo kill 'PID number'
sudo kill 91228

PID (process ID) is the four or five digit number at the end of the user readout (91228)

adm
  • 211