如何在AWS管理控制台中更改ec2实例的密钥对?我可以停止实例,我可以创建新的密钥对,但我没有看到任何链接来修改实例的密钥对。
当前回答
步骤:
创建新密钥,例如使用AWS控制台,PuTTY密钥生成器,或ssh-keygen 停止实例 设置实例用户数据以将公钥推送到服务器 启动实例
#cloud-config
cloud_final_modules:
- [once]
bootcmd:
- echo 'ssh-rsa AAAAB3Nz...' > /home/USERNAME/.ssh/authorized_keys
其中USERNAME是机器的预期用户名。可以从AWS获得默认用户名列表。
来自AWS的分步说明
其他回答
这是为他们谁有两个不同的pem文件,并出于任何安全目的想要丢弃其中一个。假设我们想要丢弃1。pem
连接到服务器2,从~/.ssh/authorized_keys中复制ssh密钥 在另一个终端上连接服务器1,并将密钥粘贴到~/.ssh/authorized_keys中。现在您将有两个公共ssh密钥 现在,为了增强自信心,尝试使用2.pem连接服务器1。您将能够将服务器1与这两个1连接。Pem和2.pem 现在,注释1。Pem SSH,使用SSH -i连接。pem user@server1
我尝试了这种方法,过了一段时间后,我能够让它工作。缺乏实际的命令让它很困难,但我想出了办法。然而,不久之后发现并测试了更简单的方法:
将实例保存为AMI(不管是否重启,我建议重启)。这只有在EBS支持的情况下才能奏效。 然后,只需从这个AMI启动一个实例并分配新的Keyfile。 将弹性IP(如果适用)转移到新实例,就完成了。
如果遵循以下步骤,将节省大量时间,也不需要停止正在运行的实例。
开始新的t1。microec2实例,使用新的密钥对。确保在相同的子网中创建它,否则将不得不终止实例并重新创建它。 SSH到新的微实例,复制~/的内容。Ssh /authorized_keys在计算机的某处。 用旧的ssh密钥登录主实例。 从点2复制并替换文件内容到~/.ssh/authorized_keys 现在您只需使用新密钥即可再次登录。旧钥匙不能用了。
就是这样。享受:)
来自AWS EC2支持的指令:
Change pem login go to your EC2 Console Under NETWORK & SECURITY, click on Key Pair Click on Create Key Pair Give your new key pair a name, save the .pem file. The name of the key pair will be used to connect to your instance Create SSH connection to your instance and keep it open in PuttyGen, click "Load" to load your .pem file Keep the SSH-2 RSA radio button checked. Click on "Save private key" You'll get pop-up window warning, click "Yes” click on "Save public key" as well, so to generate the public key. This is the public key that we're going to copy across to your current instance Save the public key with the new key pair name and with the extension .pub Open the public key content in a notepad copy the content below "Comment: "imported-openssh-key" and before "---- END SSH2 PUBLIC KEY ---- Note - you need to copy the content as one line - delete all new lines on your connected instance, open your authorized_keys file using the tool vi. Run the following command: vi .ssh/authorized_keys you should see the original public key in the file also move your cursor on the file to the end of your first public key content :type "i" for insert on the new line, type "ssh-rsa" and add a space before you paste the content of the public key , space, and the name of the .pem file (without the .pem) Note - you should get a line with the same format as the previous line press the Esc key, and then type :wq!
这将保存更新后的authorized_keys文件
现在尝试使用新的密钥pai打开一个新的SSH会话到您的实例
当您确认能够使用新的密钥对SSH进入实例时,您可以vi . SSH /authorized_key并删除旧的密钥。
对Shaggie评论的回答:
如果您无法连接到实例(例如密钥损坏),请使用AWS控制台分离卷(http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-detaching-volume.html)并将其重新连接到工作实例,然后更改卷上的密钥并将其重新连接到前一个实例。
最简单的解决方法是复制的内容
~/.ssh/id_rsa.pub
到您的AWS实例的authorized_keys at
~/.ssh/authorized_keys
这将允许您ssh进入EC2实例,而无需为ssh命令指定pem文件。测试连接后,可以删除所有其他键。
如果你需要创建一个新的密钥来与其他人共享,你可以通过:
ssh-keygen -t rsa
这将创建私钥。Pem文件,你可以通过以下方式获取该文件的公钥:
ssh-keygen -f private_key.pem -y > public_key.pub
任何拥有private_key的人。Pem能够连接到
ssh user@host.com -i private_key.pem
推荐文章
- 通过SSH使用Eclipse完成远程项目
- 如何强制从另一个SSH会话分离屏幕?
- com.jcraft.jsch.JSchException: UnknownHostKey
- 如何在Python中scp ?
- 在SSH会话中查找客户端的IP地址
- 拒绝访问;您需要(至少一个)SUPER特权来执行此操作
- 我如何使用通配符“cp”一组文件与AWS CLI
- 自定义SSH端口上的Git
- 我如何获得亚马逊的AWS_ACCESS_KEY_ID ?
- 如何使所有对象在AWS S3桶公共默认?
- Git显示“警告:永久添加到已知主机列表”
- 为什么git在Windows下记不住我的密码
- SSH端口转发~/。ssh /配置文件?
- Git克隆/拉不断冻结在“存储密钥在缓存?”
- 为什么我应该使用亚马逊Kinesis而不是SNS-SQS?