【问题标题】:Aws Ec2 ssh access - permission denied(publickey)Aws Ec2 ssh 访问 - 权限被拒绝(公钥)
【发布时间】:2016-09-19 15:30:11
【问题描述】:

看来我不是第一个为此苦苦挣扎的人。

直到现在,我通过 SSH 访问我的 EC2 实例都没有问题。到现在为止。

无论我做什么,都会收到权限被拒绝错误。我检查了我的 ec2 用户无数次,也检查了我的安全组参数。我的 IP 在入站规则中正确注册。

我尝试使用实例 DNS 和 IP。我使用 keygen -r 强制重新生成 keygen。斯蒂尔也一样。我的密钥对文件的权限为 0600。

这可能发生在实例重新启动后(不是停止/启动,来自 EC2 仪表板,而不是来自 shell)。我的实例在没有任何警报的情况下运行,并且我的网站正确显示。

我的 ssh 命令来了:

ssh -v -i "~/.ssh/namaste_3.pem" ubuntu@ec2-52-29-237-225.eu-central-1.compute.amazonaws.com

ssh -v -i "~/.ssh/keypair.pem" ubuntu@52.29.237.225

这是我的 ssh -v 输出:

OpenSSH_7.2p2 Ubuntu-4, OpenSSL 1.0.2g-fips  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 52.29.237.225 [52.29.237.225] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/brice/.ssh/namaste_3.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/brice/.ssh/namaste_3.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.4 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Authenticating to 52.29.237.225:22 as 'ubuntu'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:yiGarcstgUfXZmop1URjMPa/pp1J5mak4Rsl6TWuAh4
debug1: Host '52.29.237.225' is known and matches the ECDSA host key.
debug1: Found key in /home/brice/.ssh/known_hosts:2
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: bleroux@fluksaqua.com
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/brice/.ssh/namaste_3.pem
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
Permission denied (publickey).

有什么线索吗?我真的不想从头开始一个新实例......

【问题讨论】:

  • 试一试:你能ssh到另一台机器吗?可能是askubuntu.com/questions/343060/… 的行(其中一台机器上的权限错误)
  • 感谢您的回复。我没有另一个正在运行的实例。我从 aws 仪表板克隆了那个。嗯……那个没问题。
  • 我仍然无法访问我的旧实例,我不明白为什么。我花了几个小时才站起来……尽管这仍然是测试版,但我将不得不提升我的备份策略……

标签: amazon-ec2 ssh-keys


【解决方案1】:

如果实例是 EBS 根实例,您始终可以通过从实例中卸载根卷来诊断它,然后将其挂载到正在运行的 EC2 实例以检查 EC2 /home/ubuntu/.ssh/ 出了什么问题授权密钥。

在进行任何更改之前为卷创建快照。修复后,只需将其挂载回实例即可。

意外地尝试使用 chmod 600 来强化 EC2 /home/ubuntu/.ssh 总是会导致问题。 ~/.ssh 文件夹至少需要 u+rwx。因为正确的方法是这样的。

chmod 700 ~/.ssh
chmod 600 ~/.ssh/*

所以,文件夹总是 700。不是 600。

不要问我为什么知道这个;-)

【讨论】:

  • 感谢您的回复。我将尝试相应地更改权限,但我只是停止了实例并启动了另一个实例。只花了我几个小时。每当我确认我会回到你身边。
【解决方案2】:

首先尝试从 known_hosts 中删除条目

ssh-keygen -R hostname/IP  

然后将Key文件的权限改为400

【讨论】:

    猜你喜欢
    • 2014-07-24
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 2017-03-24
    • 2018-02-04
    • 2017-07-08
    • 2018-11-06
    • 2010-11-30
    相关资源
    最近更新 更多