我显然因为同样的权限被拒绝错误而苦苦挣扎
key_parse_private2: missing begin marker
在我的情况下,原因是当前用户的 ssh 配置文件(~/.ssh/config)。
使用以下内容:
ssh -i ~/myKey.pem ec2-user@<IP address> -v 'exit'
初始输出显示:
debug1: Reading configuration data /home/ec2-user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Hostname has changed; re-reading configuration
debug1: Reading configuration data /home/ec2-user/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
...许多调试线在这里切断...
debug1: Next authentication method: publickey
debug1: Trying private key: /home/ec2-user/somekey.pem
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey
debug1: No more authentication methods to try.
上面的第三行是发现问题的地方;但是,我从底部(上图)四行查找调试消息并被误导。密钥没有问题,但我对其进行了测试并比较了其他配置。
我的用户 ssh 配置文件通过意外的全局设置重置主机,如下所示。第一主机行不应该是评论。
$ cat config
StrictHostKeyChecking=no
#Host myAlias
user ec2-user
Hostname bitbucket.org
# IdentityFile ~/.ssh/somekey
# IdentitiesOnly yes
Host my2ndAlias
user myOtherUser
Hostname bitbucket.org
IdentityFile ~/.ssh/my2ndKey
IdentitiesOnly yes
我希望其他人会觉得这很有帮助。