Created
July 10, 2013 14:17
-
-
Save wil/5966670 to your computer and use it in GitHub Desktop.
downloads the public key from the "cloud" environment
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/sh | |
# | |
# install-root-key.sh | |
# | |
# This script downloads the public key from the "cloud" environment. | |
if [ ! -d /root/.ssh ]; then | |
mkdir -p /root/.ssh | |
chmod 700 /root/.ssh | |
fi | |
# fetch public key | |
if [ ! -s /root/.ssh/authorized_keys ]; then | |
echo "Downloading public key from instance metadata" | |
wget \ | |
--timeout=12 \ | |
--tries=50 \ | |
--waitretry=1 \ | |
--retry-connrefused \ | |
-O /root/.ssh/authorized_keys \ | |
http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key | |
if [ $? -eq 0 ]; then | |
chmod 0600 /root/.ssh/authorized_keys | |
echo "Successfully downloaded!" | |
break | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment