这是一个一般性问题,即如何诊断以下 SSH 登录跟踪中的错误。但是,我已粘贴具体细节来举例说明该问题。
主要问题陈述:
当使用“ssh -A”将密钥从一台机器转发到另一台机器时,目标机器内的 ssh 连接可能会因权限被拒绝错误而失败。但是,解释“ssh -v”命令的输出很棘手(也就是说 - 在机器有自己的 id_rsa.pub 文件的情况下,不清楚 ssh -A 是如何工作的......它会尝试使用两个公钥吗?还是只使用其中一个?)
有关 ssh 设置的一些细节
我有一台机器“A”,其中运行着一个虚拟机“B”(fedora 16)。
在 A 上,我运行
A> ssh root@B
然后,在 B 上,如果我调用“ssh-agent”,我会得到以下输出
B> ssh-agent SSH_AUTH_SOCK=/tmp/ssh-ZJRIzYHw1418/agent.1418; 导出 SSH_AUTH_SOCK; SSH_AGENT_PID=1419; 导出 SSH_AGENT_PID; echo Agent pid 1419;
最后,不确定这是否重要,但是,机器 A 和 B 都有自己的 .ssh 目录,其中包含 id_rsa.pub 密钥。这是否会导致“ssh -A”失败(即 ssh 是否足够智能,可以尝试所有可用的公钥?)
调试跟踪
>ssh -v [email protected]
OpenSSH_5.8p1, OpenSSL 1.0.0j-fips 10 May 2012
debug1: Reading configuration data /root/.ssh/config
debug1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to github.com [204.232.175.90] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type 1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5p1 Debian-6+squeeze1+github12
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze1+github12 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.8
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: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: Host 'github.com' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:10
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
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 RSA public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /root/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).
答案1
问题在于您调用的方式不ssh-agent
正确。其输出旨在由您的 shell 解释,以便设置 OpenSSH 客户端程序用来检测和与 SSH 代理通信的环境变量。由于您没有这样做,因此ssh -A
没有意识到存在可以与之通信的代理;它提供~/.ssh/id_rsa
等。因为它们存在,并且会在那里寻找默认私钥,而不是因为与不知道存在的ssh
SSH 代理有关的任何原因。ssh
如此调用ssh-agent
:
[me@box] ~ $ eval `ssh-agent`
您应该从中获得预期的结果ssh -A
。