如何使用另一个私钥/公钥对(由 PuTTY 生成)进行 ssh?

如何使用另一个私钥/公钥对(由 PuTTY 生成)进行 ssh?

我使用 PuTTY 从我的 MS Windows 工作站连接到我的一台 Linux 服务器(我使用 PuTTY 相关工具之一在 MS Windows 上生成了它们,我不记得在生成密钥时使用了哪些参数)。现在我尝试连接到同一服务器从我的 Ubuntu GNU/Linux 工作站。我的 ~/.ssh 中已经有私钥/公钥对:

id_rsa
id_rsa.pub

现在,除了我已经拥有的私钥/公钥对之外,我还想添加用于连接到我的 Linux 服务器的私钥/公钥对。对于 PuTTY,我有两个文件可以让我成功连接到我的 Linux 服务器:

emrePrivate.ppk
emrePublic.pub

我已将上述文件复制到我的 ~/.ssh 目录。然后我尝试使用以下命令连接到我的服务器:

$ ssh -v -i /home/emre/.ssh/emrePrivate.ppk [email protected]

但我发现它尝试使用错误的公钥。以下是输出:

OpenSSH_5.3p1 Debian-3ubuntu4, OpenSSL 0.9.8k 25 Mar 2009
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to yafz.org [109.74.204.147] port 22.
debug1: Connection established.
debug1: identity file /home/emre/.ssh/emrePrivate.ppk type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-6ubuntu2
debug1: match: OpenSSH_5.1p1 Debian-6ubuntu2 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3p1 Debian-3ubuntu4
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 'yafz.org' is known and matches the RSA host key.
debug1: Found key in /home/emre/.ssh/known_hosts:3
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: Offering public key: [email protected]
debug1: Authentications that can continue: publickey
debug1: Offering public key: /home/emre/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/emre/.ssh/emrePrivate.ppk
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/home/emre/.ssh/emrePrivate.ppk': 
debug1: PEM_read_PrivateKey failed
debug1: read PEM private key done: type <unknown>
Enter passphrase for key '/home/emre/.ssh/emrePrivate.ppk': 

正如您所见,它不接受我的密码。我还尝试将 emrePrivate.ppk 复制到 id_rsa,然后将 emrePublic.pub 复制到 id_rsa.pub,但我仍然无法连接到我的 Linux 服务器。

我特别担心这些话:

debug1: Offering public key: [email protected]
debug1: Authentications that can continue: publickey
debug1: Offering public key: /home/emre/.ssh/id_rsa

但我不知道如何解决这个问题。

有任何想法吗?

答案1

您的公钥必须位于目标框上的 ~/.ssh/authorized_keys 中。如果您想要其中有多个密钥,只需将它们复制到目标框并附加它们,如下所示:

cat id_rsa.pub >> ~/.ssh/authorized_keys

另外,阅读此信息关于 putty 密钥兼容性以及如何转换密钥。

相关内容