Skip to content

Instantly share code, notes, and snippets.

@Oisann
Last active May 1, 2024 21:09
Show Gist options
  • Save Oisann/f8cd668e2e4aa642f857ec31d8104ba4 to your computer and use it in GitHub Desktop.
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)
#!/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
@Oisann
Copy link
Author

Oisann commented May 1, 2024

$HOSTNAME should be $HOST on macOS, it seems

@Oisann
Copy link
Author

Oisann commented May 1, 2024

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