gh-19: tidy up ssh key script

pull/20/head
Javi Fontan 9 years ago
parent 66b8474374
commit e371ddecfa

@ -16,19 +16,22 @@
# limitations under the License. # # limitations under the License. #
#--------------------------------------------------------------------------- # #--------------------------------------------------------------------------- #
AUTH_DIR="/root/.ssh"
AUTH_FILE="$AUTH_DIR/authorized_keys"
function add_keys { function add_keys {
while read key; do while read key; do
if ! grep -q -F "$key" /root/.ssh/authorized_keys; then if ! grep -q -F "$key" $AUTH_FILE; then
echo "$key" >> /root/.ssh/authorized_keys echo "$key" >> $AUTH_FILE
fi fi
done done
} }
[ -z "${SSH_PUBLIC_KEY}${EC2_PUBLIC_KEY}" ] && exit 0 [ -z "${SSH_PUBLIC_KEY}${EC2_PUBLIC_KEY}" ] && exit 0
[ ! -f /root/.ssh/authorized_keys ] && touch /root/.ssh/authorized_keys [ ! -f $AUTH_FILE ] && touch $AUTH_FILE
mkdir -m0700 -p /root/.ssh mkdir -m0700 -p $AUTH_DIR
if [ -n "$SSH_PUBLIC_KEY" ]; then if [ -n "$SSH_PUBLIC_KEY" ]; then
echo "$SSH_PUBLIC_KEY" | add_keys echo "$SSH_PUBLIC_KEY" | add_keys
@ -38,4 +41,4 @@ if [ -n "$EC2_PUBLIC_KEY" ]; then
echo "$EC2_PUBLIC_KEY" | add_keys echo "$EC2_PUBLIC_KEY" | add_keys
fi fi
chmod 600 /root/.ssh/authorized_keys chmod 600 $AUTH_FILE

Loading…
Cancel
Save