Skip to content

Instantly share code, notes, and snippets.

@holmberd
Last active April 25, 2024 15:50
Show Gist options
  • Star 42 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save holmberd/b09fb15e9a49d60ac44ea7ff6fb1b6bb to your computer and use it in GitHub Desktop.
Save holmberd/b09fb15e9a49d60ac44ea7ff6fb1b6bb to your computer and use it in GitHub Desktop.
Kill tty/pts sessions in Linux

Kill user tty/pts sessions in Linux

Commands

  • w: show who is logged on and what they are doing
  • who: show who is logged on
  • tty: show current users pseudo terminal
  • ps -ft pts/1: get process id for the pseudo terminal
  • pkill: signal process based on name and other attributes
  1. Check active users logged into the server with: w
 16:53:37 up 23:46,  2 users,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
ubuntu   pts/1    24.69.132.96     16:45    0.00s  0.04s  0.00s w
ubuntu   pts/2    24.69.132.96:S.0 16:35   16.00s  0.02s  0.02s /bin/bash
  1. Get the PID (Process ID) of a connected terminal (tty) with: ps -ft pts/1
UID        PID  PPID  C STIME TTY          TIME CMD
ubuntu   28580 28102  0 16:45 pts/1    00:00:00 -bash
ubuntu   29081 28580  0 16:55 pts/1    00:00:00 ps -ft pts/1
  1. Kill the process: kill 28580

  2. Alternatively use pkill -t pts/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment