How to Terminate Stuck or Unwanted User Sessions in Linux
To terminate the user session of the remotely logged-in user “linuxiac,” we will use the pkill
command in Linux with the option “-KILL,” which means that the Linux process must be terminated immediately (not gracefully). Use the “-t” flag to specify the name of the TTY.
pkill -KILL -t pts/1
The second approach we will show you uses terminating a user session by process ID. To do this, we execute the w command again to get a list of logged-in users along with their associated TTY/PTS.
Then, once we’ve identified the TTY/PTS session, use the ps command with “-ft” parameters to find its PID:
ps -ft [TTY/PTS]
Code language: CSS (css)
Finally, use the kill command with “-9” (unconditionally terminate a process) switch passing the process ID. For example:
kill -9 4374