Last active
May 1, 2024 21:09
-
-
Save Oisann/f8cd668e2e4aa642f857ec31d8104ba4 to your computer and use it in GitHub Desktop.
Connect to ssh servers with temporary keys (for public servers like terminal.shop)
This file contains 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/zsh | |
REMOTE_SERVER=$1 | |
REPLACEMENT="anon@ubuntu" | |
LOGIN="$USER@$HOSTNAME" | |
WD=`mktemp -d` | |
pushd $WD > /dev/null | |
ssh-keygen -t rsa -b 4096 -q -f "$WD/id_rsa" -N "" | |
sed -i -e "s/$LOGIN/$REPLACEMENT/g" "$WD/id_rsa.pub" | |
chmod 400 "$WD/id_rsa" | |
chmod 400 "$WD/id_rsa.pub" | |
ssh -T -t -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -o "IdentitiesOnly=yes" -i "$WD/id_rsa.pub" $REMOTE_SERVER < /dev/tty | |
popd > /dev/null | |
cleanup() { | |
rm -rf "$WD" | |
} | |
trap cleanup EXIT INT QUIT TERM |
I also get invalid key on macOS, so I'm not sure what's wrong.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$HOSTNAME
should be$HOST
on macOS, it seems