You might need to forcefully let logged-in users in your system log out when doing some administrative work or when a rogue or unidentified user is acting maliciously.

If you have physical access to the server, you could unplug the network connection and reboot the system. That might not always be possible, such as when working on remotes servers via SSH. To forcefully log a user out of the system, you'll need to kill processes owned by the user to terminate whatever session the user currently has.

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 the user is still logged in after a while.

    $ sudo pkill -9 -u shakir