Skip to content

Instantly share code, notes, and snippets.

@rhovelz
Created September 10, 2024 03:27
Show Gist options
  • Save rhovelz/40e90213e81d519e9848077e61c856e4 to your computer and use it in GitHub Desktop.
Save rhovelz/40e90213e81d519e9848077e61c856e4 to your computer and use it in GitHub Desktop.

$ who -u

  • savona pts/1 2019-03-16 09:46 . 6063 (192.168.122.1)

  • stacy pts/0 2019-03-16 17:07 . 9940 (192.168.122.1)

  • echo "Your session will be terminated in 2 minutes for maintenance." | write stacy pts/0

End the Users Shell Process

When you are ready to kick the user, send the SIGHUP to the users shell process. A SIGHUP signal is the same signal the process would receive when the controlling terminal is closed.

  • sudo kill -HUP 9940

The number at the end of the above command is the process ID of the users shell. We found the process ID using the who command above. Sometimes there is a process that hangs. In that case we can send a SIGKILL (kill -9) to the PID. This is exactly what it sounds like. It will immediately terminate ANY process, so be careful.

  • sudo kill -9 9940

My preferred way of kicking a user it to use pkill to send a SIGHUP to all of the users processes. The pkill command is a wrapper for kill and allows for signalling a process by name rather than PID (process ID).

  • sudo pkill -HUP -u stacy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment