Skip to content

Instantly share code, notes, and snippets.

@0x27
Created February 28, 2019 12:01
Show Gist options
  • Save 0x27/0f0ee4c2613457dfcf7ee318b892201c to your computer and use it in GitHub Desktop.
Save 0x27/0f0ee4c2613457dfcf7ee318b892201c to your computer and use it in GitHub Desktop.
#!/bin/bash
echo "SSH hangup user tool. For killing other users connections."
if [ $# -eq 0 ]
then
echo "use: $0 <PTS number to kill>"
exit
fi
echo "Terminating PTS/$1"
OWNER=$(stat -c '%U' /dev/pts/$i)
SSH_PID=$(pgrep -a sshd | grep pts/$1 | cut -d ' ' -f 1)
echo "Owner of PTS is $OWNER"
echo "SSH PID is $SSH_PID"
echo "You have been expunged." > /dev/pts/$1
sleep 2 # we sleep for a sec here, to ensure they get the message
kill -9 $SSH_PID
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment