Skip to content

Instantly share code, notes, and snippets.

@wil
Created July 10, 2013 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wil/5966670 to your computer and use it in GitHub Desktop.
Save wil/5966670 to your computer and use it in GitHub Desktop.
downloads the public key from the "cloud" environment
#!/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