Last active
October 19, 2021 11:41
-
-
Save Groverkss/589eae5aacf40c767d3985471ac004ff to your computer and use it in GitHub Desktop.
Kill all ssh user sessions other than the current one
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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