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