Skip to content

Instantly share code, notes, and snippets.

@emdnaia
Last active October 20, 2025 01:07
Show Gist options
  • Select an option

  • Save emdnaia/e39aabe992d5829e432974c14b151b94 to your computer and use it in GitHub Desktop.

Select an option

Save emdnaia/e39aabe992d5829e432974c14b151b94 to your computer and use it in GitHub Desktop.
MY_TTY=$(tty | sed 's/\/dev\///')
MY_SESSION_PIDS=$(ps aux | grep "sshd-session.*$MY_TTY" | awk '{print $2}' | tr '\n' '|' | sed 's/|$//')
echo "Protecting PIDs: $MY_SESSION_PIDS"
while true; do
ps aux | grep 'sshd-session' | grep -v grep | grep -v '\[listener\]' | awk '{print $2}' | grep -vE "^($MY_SESSION_PIDS)$" | xargs -r kill -9 2>/dev/null
sleep 0.01 # Check every 10ms - way faster
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment