-
-
Save ehershey/3c795c15da16b39a1dbf to your computer and use it in GitHub Desktop.
This file contains hidden or 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/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