我显然是由于相同的许可被拒绝错误而挣扎
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
我希望其他人对此有所帮助。