简体   繁体   English

Amazon EC2公钥错误

[英]Amazon EC2 publickey error

I had a developer working on my app prior to now. 我之前有一个开发人员在开发我的应用程序。 I am taking over the project, as he is now out of the country, and can't get an SSH connection established. 我正在接手该项目,因为他现在不在国外,并且无法建立SSH连接。 I keep getting a publickey error. 我不断收到公钥错误。

Steps taken: 采取的步骤:

- Created new key pair  
- Downloaded .pem file  
- Set chmod 400 on .pem file  
- ssh -vvv -i ~/.ssh/steve.pem ubuntu@instance ip

Verbose output ended with: 详细输出以以下结尾:

debug2: we sent a publickey packet, wait for reply  
debug1: Authentications that can continue: publickey  
debug2: we did not send a packet, disable method  
debug1: No more authentication methods to try.  
Permission denied (publickey).  

What am I doing wrong? 我究竟做错了什么?

You can't create a new key pair to access an existing instance. 您无法创建新的密钥对来访问现有实例。 The keypair selected is only installed on the instance when its launched, any additional keys have to be added to the instance directly. 选定的密钥对仅在实例启动时安装在实例上,任何其他密钥都必须直接添加到实例。

If you need to add a new key to an existing instance, you can do the following: 如果需要向现有实例添加新密钥,则可以执行以下操作:

  1. Stop your instance. 停止您的实例。
  2. Detach the root volume. 分离根卷。
  3. Attach to a new instance as a secondary volume and mount the volume. 附加到新实例作为辅助卷并挂载该卷。
  4. Update the ~/.ssh/authorized_keys file for the user you are trying to login with. 为您尝试登录的用户更新〜/ .ssh / authorized_keys文件。 You would put your new public key in this file. 您可以将新的公钥放入此文件中。
  5. Unmount the volume, and reattach it to the original instance. 卸载该卷,然后将其重新连接到原始实例。

If you did everything right, you will be able to access the instance after you restart. 如果一切正确,重启后将可以访问实例。 Unless your in VPC your ip will change when you stop the instance. 除非您在VPC中,否则停止实例时,您的IP将更改。

I agree with datasage's answer. 我同意datasage的回答。 Another way to get access is to create an AMI image of the current instance and then launch a new instance from that image. 获得访问权限的另一种方法是创建当前实例的AMI映像,然后从该映像启动新实例。 When you launch the new instance, you will have the option to create a new key pair or to use an existing one. 启动新实例时,可以选择创建新密钥对或使用现有密钥对。

Once you can connect to the new instance, you can reassign the Elastic IP (if any) of the old instance to the new one and just terminate the old instance. 一旦可以连接到新实例,就可以将旧实例的弹性IP(如果有)重新分配给新实例,然后终止旧实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM