You might need to forcefully let logged in users in you system to log out when you are doing some administrative work or when a rogue or unidentified user is acting maliciously. This could be the case for Linux servers running SSH.

If you have physical access to the server you could just unplug the network connection and then reboot the system. That's not always possible so you'll need to kill processes owned by the user to terminate whatever session the user currently have in the system.

Steps to kick out user in Linux:

  1. Launch terminal.
  2. List currently logged in user in the system.
    $ who
    user     :0           2021-01-23 16:23 (:0)
    shakir   pts/1        2021-01-23 16:31 (192.168.111.1)
  3. List all processes owned by the user you want to kick out of the system.
    $ ps -U shakir
        PID TTY          TIME CMD
       2086 ?        00:00:00 systemd
       2087 ?        00:00:00 (sd-pam)
       2093 ?        00:00:00 pulseaudio
       2097 ?        00:00:00 tracker-miner-f
       2106 ?        00:00:00 dbus-daemon
       2126 ?        00:00:00 gvfsd
       2135 ?        00:00:00 gvfsd-fuse
       2136 ?        00:00:00 gvfs-udisks2-vo
       2149 ?        00:00:00 gvfs-mtp-volume
       2153 ?        00:00:00 gvfs-goa-volume
       2157 ?        00:00:00 goa-daemon
       2177 ?        00:00:00 goa-identity-se
       2186 ?        00:00:00 gvfs-afc-volume
       2194 ?        00:00:00 gvfs-gphoto2-vo
       2248 ?        00:00:00 sshd
       2249 pts/1    00:00:00 bash
  4. Kill user's terminal or other session processes.
    $ sudo kill 2249
    [sudo] password for user:

    bash is normally the process if the user is connected via SSH.

  5. Alternatively, kill all processes owned by the user.
    $ sudo pkill -u shakir

  6. Check if user still logged in.
    $ who
    user     :0           2021-01-23 16:23 (:0)
  7. Force process termination if user is still logged in after a while.
    $ sudo pkill -9 -u shakir
Discuss the article:

Comment anonymously. Login not required.

Share!