为什么我的 ssh 私钥密码不起作用(在 Mac 上)?

为什么我的 ssh 私钥密码不起作用(在 Mac 上)?

我有一对私钥和公钥。公钥在我的服务器上,私钥在我的本地磁盘上。使用以下命令更改了文件的权限:

chmod 600 private_key

现在我尝试使用以下命令登录我的服务器:

ssh -i path_to_the_private_key username@servername

我的 Mac 显示一个对话框并要求我输入密码。我输入了密码,但 Mac 说密码不正确。

当我使用相同的私钥通过 putty 和相同的密码登录到同一个服务器时,一切都运行良好。

有什么提示吗?

ssh 命令的输出:

OpenSSH_5.2p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: Connecting to servername [...] port 22.
debug1: Connection established.
debug1: identity file private_key_su.ppk type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8p1 Debian-7ubuntu1
debug1: match: OpenSSH_5.8p1 Debian-7ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.2
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 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: Host 'servername' is known and matches the RSA host key.
debug1: Found key in path:4
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: private_key_su.ppk
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
debug1: No more authentication methods to try.
Permission denied (publickey).

答案1

我相信 OpenSSH 和 Putty 对私钥文件使用不同的格式。您可以将私钥加载到 PuttyGen 并将其转换为 OpenSSH 格式

PuttyGen 菜单

答案2

我也遇到过同样的问题,唯一的不同就是我的私钥文件是 pem 格式,而你的是 ppk。我通过在 TextWrangler 中打开私钥文件解决了这个问题,将编码从“Unicode (UTF-8, with BOM)”更改为“Unicode (UTF-8)”,并将换行符从“Classic Mac (CR)”更改为“Windows (CRLF)”。我知道这似乎有点倒退,但这是我所做的唯一更改,而且它确实有效。

文件设置位于 TextWrangler 窗口的底部。

相关内容