Last active
December 2, 2020 06:27
-
-
Save relaxdiego/d35dccb74bd4703e582b16454141ef5e to your computer and use it in GitHub Desktop.
If you can't be bothered to implement cert-based SSH...
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
#!/usr/bin/env bash | |
ip_address=$( | |
aws ec2 describe-instances --instance-id $instance_id | \ | |
jq -r ".Reservations[] | .Instances[] | select(.InstanceId==\"$instance_id\") | .PublicIpAddress" | |
) | |
if ! grep $ip_address ~/.ssh/known_hosts >/dev/null; then | |
# Print the SSH fingerprints for jumpbox | |
echo "Valid server key fingerprints:" | |
aws ec2 get-console-output --instance-id $instance_id | \ | |
jq -r '.Output' | \ | |
awk '/-----BEGIN SSH HOST KEY FINGERPRINTS-----/{flag=1; next} /-----END SSH HOST KEY FINGERPRINTS-----/{flag=0} flag' | \ | |
awk '{print $6}' | |
echo -e "\nUse one of the above lines to verify the remote's identity\n" | |
fi | |
ssh ubuntu@$ip_address |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: