gpt4 book ai didi

linux - EC2 key 对在一个实例中有效但在其他实例中失败 - 权限被拒绝(公钥)

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:33:46 25 4
gpt4 key购买 nike

我已经阅读了很多关于这个主题的帖子,但没有一个能帮助我解决我的问题。

我有一台机器 amazon ec2,我使用这个 SSH 命令连接它:

ssh -i /Library/AWS/glrpopulis.pem ec2-user@54.225.154.23

到目前为止,我在使用此命令时从未遇到过问题。它刚刚停止工作,显示以下消息:Permission denied (publickey)。 莫名其妙!

我真的不明白为什么我几乎每天都使用的同一个命令突然失效了。可能我更改了一些我不应该更改的内容,但我真的很难弄清楚是什么。

第一次发生这种情况时,我正在为 Web 应用程序 (atlassian bamboo) 创建服务,但我不确定这是否与错误有关。

我已经重启了几次机器并反复尝试,但没有成功。

带有 -v 选项的完整输出如下所示:

mac-pipo:~ felipereis$ ssh -v -i /Library/AWS/glrpopulis.pem ec2-user@54.225.154.23
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to 54.225.154.23 [54.225.154.23] port 22.
debug1: Connection established.
debug1: identity file /Users/felipereis/.ssh/id_rsa type 1
debug1: identity file /Users/felipereis/.ssh/id_rsa-cert type -1
debug1: identity file /Users/felipereis/.ssh/id_dsa type -1
debug1: identity file /Users/felipereis/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 19:ef:f1:2b:56:dd:86:ec:42:65:ff:1d:6b:64:0f:f3
debug1: Host '54.225.154.23' is known and matches the RSA host key.
debug1: Found key in /Users/felipereis/.ssh/known_hosts:12
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/felipereis/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Offering RSA public key: /Library/AWS/glrpopulis.pem
debug1: Authentications that can continue: publickey
debug1: Trying private key: /Users/felipereis/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).

更新:* 我刚刚测试过,我能够使用相同的 key (glrpopulis.pem) 连接到不同的 ec2 实例,所以第一台机器上可能发生了什么

最佳答案

听起来 ~/.ssh/authorized_keys 下的 key 被弄乱了或者文件被删除了。

尝试以下操作:

  1. 停止您的 EC2 实例
  2. 分离根卷 (/dev/sda1) -- 假设这是 Volume A
  3. 启动一个具有相同类型和相同凭据的新 EC2 实例。
  4. Volume A 作为 /dev/sdf 附加到该新实例>
  5. ssh 连接到他的新实例。
  6. mkdir -p/mnt/xvdf
  7. 挂载/dev/xvdf/mnt/xvdf
  8. cp ~/.ssh 到/mnt/xvdf/home/ec2-user/。
  9. chmod 700/mnt/xvdf/home/ec2-user
  10. chmod 600/mnt/xvdf/home/ec2-user/authorized_keys
  11. 关闭新实例
  12. 在新实例上分离 Volume A
  13. 在原始实例的/dev/sda1 上重新附加 Volume A
  14. 启动原始实例。

您现在应该可以登录了。

关于linux - EC2 key 对在一个实例中有效但在其他实例中失败 - 权限被拒绝(公钥),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23068591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com