aws ec2 开机自动配置登录密钥

/etc/init.d/updatessh.sh

#!/bin/bash
if [ ! -d /home/ec2-user/.ssh ] ; then
        mkdir -p /home/ec2-user/.ssh
        chmod 700 /home/ec2-user/.ssh
fi
# Fetch public key using HTTP
curl -s  http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > /tmp/my-key
if [ $? -eq 0 ] ; then
        cat /tmp/my-key > /home/ec2-user/.ssh/authorized_keys
        chmod 700 /home/ec2-user/.ssh/authorized_keys
        rm /tmp/my-key
fi

 

posted @ 2019-03-21 15:07  老农夫  阅读(335)  评论(0编辑  收藏  举报