Skip to content

Instantly share code, notes, and snippets.

@dougpagani
Created March 30, 2022 16:55
Show Gist options
  • Save dougpagani/cd0354c5b204001166c8446c410cb977 to your computer and use it in GitHub Desktop.
Save dougpagani/cd0354c5b204001166c8446c410cb977 to your computer and use it in GitHub Desktop.
ssh-isolate-access() {
cat ~/.ssh/id_rsa.pub | command ssh "$@" '
cat > ~/newakeys;
nohup bash -c '"'"'trap "" HUP; echo $$ > ~/killme && sleep 10 && mv -f ~/authorized_keys ~/.ssh/authorized_keys;'"'"' </dev/null &>/dev/null & disown;
mv ~/.ssh/authorized_keys ~/authorized_keys &&
mv ~/newakeys ~/.ssh/authorized_keys;
echo DONE: close connection
'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment