简体   繁体   English

AWS_EC2 ssh 权限被拒绝(公钥)

[英]AWS_EC2 ssh Permission denied (publickey)

Ugh, so I've read every SO solution and nothing has worked.呃,所以我已经阅读了每个 SO 解决方案,但没有任何效果。

Long story short, apple reformatted my computer and I lost my Private key to ssh into my aws ec2 linux instance.长话短说,苹果重新格式化了我的电脑,但我丢失了通过 ssh 进入我的 aws ec2 linux 实例的私钥。 I generated a new key, changed the permissions to 400 and tried to ssh but I'm getting:我生成了一个新密钥,将权限更改为 400 并尝试 ssh,但我得到:

Permission denied (publickey).

when i use the -v option I'm seeing:当我使用 -v 选项时,我看到:

ssh: Could not resolve hostname [path-to-my-new-pem]: nodename nor servname provided, or not known

any ideas?有任何想法吗?

when you say that you generated a new key, you still need to import the key pair into the EC2 instance, which obviously you cannot since you lost the current private key.当您说您生成了一个新密钥时,您仍然需要将密钥对导入到 EC2 实例中,这显然不能,因为您丢失了当前的私钥。 ok so how to move it from there.好的,那么如何从那里移动它。

You need the key pair to be uploaded into the ~/.ssh/authorized_keys您需要将密钥对上传到 ~/.ssh/authorized_keys

The procedure is explained in amazon doc Connecting to Your Linux Instance if You Lose Your Private Key该过程在 amazon doc Connecting to Your Linux Instance if You Lost Your Private Key 中进行了说明

basically you need to:基本上你需要:

  • create a new key pair from AWS console从 AWS 控制台创建新的密钥对
  • Stop your current instance (do not terminate as you would loose the current data)停止您的当前实例(不要terminate因为您会丢失当前数据)
  • detach the current Volume V of the instance分离实例的当前卷 V
  • Launch a new instance (* specify the same Availability Zone as the instance you'd like to connect to. If you're launching an instance in a VPC, select a subnet in this Availability Zone.*)启动新实例(* 指定与您要连接的实例相同的可用区。如果您要在 VPC 中启动实例,请在此可用区中选择一个子网。*)
  • Attach the volume V to the new instance将卷 V 附加到新实例

--> now you have access to all your data, update the authorized_keys with the new key pair --> 现在你可以访问你的所有数据了,用新的密钥对更新authorized_keys

  • detach again the volume V from the new instance and attach it back to the old instance再次从新实例分离卷 V 并将其附加回旧实例
  • start the new instance启动新实例
  • ssh with the new key pair使用新密钥对 ssh

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

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