From e371ddecfa568e2742847849efb9e5a22f426c8c Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 3 Sep 2015 15:04:45 +0200 Subject: [PATCH] gh-19: tidy up ssh key script --- base/etc/one-context.d/02-ssh_public_key | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/base/etc/one-context.d/02-ssh_public_key b/base/etc/one-context.d/02-ssh_public_key index 3c8edbb..da5f184 100755 --- a/base/etc/one-context.d/02-ssh_public_key +++ b/base/etc/one-context.d/02-ssh_public_key @@ -16,19 +16,22 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +AUTH_DIR="/root/.ssh" +AUTH_FILE="$AUTH_DIR/authorized_keys" + function add_keys { while read key; do - if ! grep -q -F "$key" /root/.ssh/authorized_keys; then - echo "$key" >> /root/.ssh/authorized_keys + if ! grep -q -F "$key" $AUTH_FILE; then + echo "$key" >> $AUTH_FILE fi done } [ -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 echo "$SSH_PUBLIC_KEY" | add_keys @@ -38,4 +41,4 @@ if [ -n "$EC2_PUBLIC_KEY" ]; then echo "$EC2_PUBLIC_KEY" | add_keys fi -chmod 600 /root/.ssh/authorized_keys +chmod 600 $AUTH_FILE