Skip to content

Instantly share code, notes, and snippets.

@ehershey
Forked from jbreams/gist:f9f5d6a7aafd26072cd3
Last active August 29, 2015 14:06
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 ehershey/3c795c15da16b39a1dbf to your computer and use it in GitHub Desktop.
Save ehershey/3c795c15da16b39a1dbf to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Init file for AWS Authorized Keyfile
#
# chkconfig: 2345 11 25
# description: AWS Authorized Keyfile
case $1 in
start)
touch /var/lock/subsys/awssshkey
;;
stop)
rm /var/lock/subsys/awssshkey
exit 0
;;
esac
if [ ! -d /root/.ssh ]; then
mkdir -m 0700 -p /root/.ssh
restorecon /root/.ssh
fi
# Get the root ssh key setup
ReTry=0
rm -f /root/.ssh/authorized_keys
while [ ! -f /root/.ssh/authorized_keys ] && [ $ReTry -lt 5 ]; do
sleep 2
curl -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key \
> /root/.ssh/authorized_keys
[ $? -eq 0 ] && echo "Added ssh keys $(< /root/.ssh/authorized_keys)"
ReTry=$[Retry+1]
done
chmod 600 /root/.ssh/authorized_keys && restorecon /root/.ssh/authorized_keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment