如何使用 PuTTY 转发密钥

Noc*_*che 11 ssh putty ssh-keys

我的情况: - 我通过(使用我的私钥和密码)从我的 PC (Windows 7) 连接到服务器 A userA- 我想通过命令 ssh: 从 A 连接到服务器 B ssh userB@serverName,但是我收到“权限被拒绝”。

对于每台服务器,我的密钥都存在于文件夹中ssh\authorized_keys。甚至,如果我可以直接从我的 PC 连接到服务器 B,并且如果我尝试从服务器 A 连接,我会收到此错误。

使用 Linux 的人成功地使用命令ssh -A连接到服务器 B。我相信 PuTTY 选项“代理转发”是等效的,但..不,仍然是相同的错误。

ssh当我尝试从服务器 A 连接到服务器 B 时,从登录:

OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to serverB port 22.
debug1: Connection established.
debug1: identity file /home/userA/.ssh/identity type -1
debug1: identity file /home/userA/.ssh/id_rsa type -1
debug1: identity file /home/userA/.ssh/id_dsa type -1
debug1: loaded 3 keys
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_4.3
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc 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 'serverB' is known and matches the RSA host key.
debug1: Found key in /home/userA/.ssh/known_hosts:2
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
*******************************************************************************
*            This equipment is the propertyof            *
*                    UNAUTHORIZED ACCESS WILL BE PROSECUTED                   *
*******************************************************************************
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
Unknown code krb5 195

debug1: Unspecified GSS failure.  Minor code may provide more information
Unknown code krb5 195

debug1: Unspecified GSS failure.  Minor code may provide more information
Unknown code krb5 195

debug1: Next authentication method: publickey
debug1: Trying private key: /home/userA/.ssh/identity
debug1: Trying private key: /home/userA/.ssh/id_rsa
debug1: Trying private key: /home/userA/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
Run Code Online (Sandbox Code Playgroud)

use*_*686 26

是的,该选项是等效的,但是,它通常不转发密钥-专门将连接转发到“SSH 代理”。“代理”将您的密钥保存在内存中,解密后(因此您只需要解锁一次),并且客户端要求它对数据进行签名以进行身份​​验证。

在 Linux/Unix/BSD/Cygwin 上,OpenSSH 的代理程序是ssh-agent(虽然在某些情况下它被 gpg-agent 或 gnome-keyring 取代,但在这里无关紧要)。

同时,Windows 上的 PuTTY 也有 pageant.exe同样的目的。(其他程序,例如 WinSCP,也使用 Pageant。)

首先,启动代理并将您的密钥加载到其中。(双击 .ppk 密钥文件就足够了。)现在,当您 PC 上的 PuTTY 连接到服务器 A 时,它将使用您的 PC 上运行的代理中的密钥,而不是 .ppk 文件中的密钥。

  • PC 上的选美(代理)?PC(客户端)上的 PuTTY ? serverA(服务器)上的 sshd

同样,当您在服务器 A 上运行时ssh serverB,它会尝试联系在服务器 A 上运行的代理。

  • ???(代理人) ?serverA(客户端)上的 ssh ?serverB(服务器)上的 sshd

如果您在-A启用“代理转发”或选项的情况下连接到服务器 A ,则 PuTTY 将中继代理连接,并且ssh在服务器 A 上将能够使用来自您 PC 上的代理的密钥。

  • PC 上的选美(代理)?PC 上的 PuTTY(转发客户端) ? serverA(转发服务器)上的 sshd ?serverA(客户端)上的 ssh ?serverB(服务器)上的 sshd