Skip to content

Instantly share code, notes, and snippets.

@Groverkss
Last active October 19, 2021 11:41
Show Gist options
  • Save Groverkss/589eae5aacf40c767d3985471ac004ff to your computer and use it in GitHub Desktop.
Save Groverkss/589eae5aacf40c767d3985471ac004ff to your computer and use it in GitHub Desktop.
Kill all ssh user sessions other than the current one
#!/bin/bash
# Credit: https://unix.stackexchange.com/a/397914/469786
# https://askubuntu.com/questions/902998/how-to-check-which-tty-im-currently-using
#
# This command is useful when ssh connection drops and the ssh sessions still presist.
function kssh {
allshs=$(w | tail -n+3 | awk '{print $2}')
curshs=$(who am i | head -n1 | awk '{print $2}')
for i in $(echo $allshs | grep -v $curshs); do fuser -k /dev/"$i"; done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment