From e04ab3383f9965e0d539c34bac60be5d6b2c2811 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 3 Sep 2015 12:19:07 +0200 Subject: [PATCH] gh-19: don't overwrite authorized keys --- base/etc/one-context.d/02-ssh_public_key | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/base/etc/one-context.d/02-ssh_public_key b/base/etc/one-context.d/02-ssh_public_key index cb83b2d..2057636 100755 --- a/base/etc/one-context.d/02-ssh_public_key +++ b/base/etc/one-context.d/02-ssh_public_key @@ -16,18 +16,24 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +function add_keys { + while read key; do + if ! grep -q -F "$key" /root/.ssh/authorized_keys; then + echo "$key" >> /root/.ssh/authorized_keys + fi + done +} + [ -z "${SSH_PUBLIC_KEY}${EC2_PUBLIC_KEY}" ] && exit 0 mkdir -m0700 -p /root/.ssh -echo -n '' > /root/.ssh/authorized_keys - if [ -n "$SSH_PUBLIC_KEY" ]; then - echo "$SSH_PUBLIC_KEY" >> /root/.ssh/authorized_keys + echo "$SSH_PUBLIC_KEY" | add_keys fi if [ -n "$EC2_PUBLIC_KEY" ]; then - echo "$EC2_PUBLIC_KEY" >> /root/.ssh/authorized_keys + echo "$EC2_PUBLIC_KEY" | add_keys fi chmod 600 /root/.ssh/authorized_keys