尝试通过SSH与代理转发进行连接时,我得到的权限被拒绝。 我有四个机器:我的本地盒子(我),私人服务器(私人),公共网关,可以路由到私人服务器(网关),和公共服务器(目的地)。
如果我需要连接到“目标”或“网关”,我可以简单地执行以下操作,validation我的密钥对于两台主机是否有效:
me@me:~$ ssh -i my.key destination me@me:~$ ssh -i my.key gateway
如果我需要连接到“私人”,我可以执行以下操作,validation代理转发是否按预期工作,并且我的密钥对于主机有效:
me@me:~$ ssh -Ati my.key gateway me@gateway:~$ ssh private
如果需要从“网关”连接到“目的地”,我可以执行以下操作,validation连接到目的地时的代理转发工作:
me@me:~$ ssh -Ati my.key gateway me@gateway:~$ ssh destination
如果我需要从“私人”连接到“目的地”,我应该能够做到以下几点:
me@me:~$ ssh -Ati my.key gateway me@gateway:~$ ssh -At private me@private:~$ ssh destination
但是,当我尝试最后一个命令,我收到Permission denied (publickey). 如果我以冗长的方式运行,我会得到以下结果:
OpenSSH_6.6.1, OpenSSL 1.0.1k-fips 8 Jan 2015 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 56: Applying options for * debug2: ssh_connect: needpriv 0 debug1: Connecting to destination [52.35.125.100] port 22. debug1: Connection established. debug1: identity file /home/me/.ssh/id_rsa type -1 debug1: identity file /home/me/.ssh/id_rsa-cert type -1 debug1: identity file /home/me/.ssh/id_dsa type -1 debug1: identity file /home/me/.ssh/id_dsa-cert type -1 debug1: identity file /home/me/.ssh/id_ecdsa type -1 debug1: identity file /home/me/.ssh/id_ecdsa-cert type -1 debug1: identity file /home/me/.ssh/id_ed25519 type -1 debug1: identity file /home/me/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.6.1 debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1 debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000 debug2: fd 3 setting O_NONBLOCK debug3: load_hostkeys: loading entries for host "destination" from file "/home/me/.ssh/known_hosts" debug3: load_hostkeys: found key type ECDSA in file /home/me/.ssh/known_hosts:7 debug3: load_hostkeys: loaded 1 keys debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521 debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug2: kex_parse_kexinit: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ssh-rsa,ssh-dss debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected] debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected] debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: none,[email protected],zlib debug2: kex_parse_kexinit: none,[email protected],zlib debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: kex_parse_kexinit: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 debug2: kex_parse_kexinit: ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519 debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected] debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected] debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96 debug2: kex_parse_kexinit: none,[email protected] debug2: kex_parse_kexinit: none,[email protected] debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: debug2: kex_parse_kexinit: first_kex_follows 0 debug2: kex_parse_kexinit: reserved 0 debug2: mac_setup: setup [email protected] debug1: kex: server->client aes128-ctr [email protected] none debug2: mac_setup: setup [email protected] debug1: kex: client->server aes128-ctr [email protected] none debug1: kex: [email protected] need=16 dh_need=16 debug1: kex: [email protected] need=16 dh_need=16 debug1: sending SSH2_MSG_KEX_ECDH_INIT debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ECDSA 01:2f:4e:3f:b3:a3:92:0f:29:e0:72:d7:d1:2c:af:4b debug3: load_hostkeys: loading entries for host "destination" from file "/home/me/.ssh/known_hosts" debug3: load_hostkeys: found key type ECDSA in file /home/me/.ssh/known_hosts:7 debug3: load_hostkeys: loaded 1 keys debug3: load_hostkeys: loading entries for host "52.35.125.100" from file "/home/me/.ssh/known_hosts" debug3: load_hostkeys: found key type ECDSA in file /home/me/.ssh/known_hosts:8 debug3: load_hostkeys: loaded 1 keys debug1: Host 'destination' is known and matches the ECDSA host key. debug1: Found key in /home/me/.ssh/known_hosts:7 debug1: ssh_ecdsa_verify: signature correct debug2: kex_derive_keys debug2: set_newkeys: mode 1 debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug2: set_newkeys: mode 0 debug1: SSH2_MSG_NEWKEYS received debug1: SSH2_MSG_SERVICE_REQUEST sent debug2: service_accept: ssh-userauth debug1: SSH2_MSG_SERVICE_ACCEPT received debug2: key: me@me (0x5611e148efd0), debug2: key: /home/me/.ssh/id_rsa ((nil)), debug2: key: /home/me/.ssh/id_dsa ((nil)), debug2: key: /home/me/.ssh/id_ecdsa ((nil)), debug2: key: /home/me/.ssh/id_ed25519 ((nil)), debug1: Authentications that can continue: publickey debug3: start over, passed a different list publickey debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Offering RSA public key: me@me debug3: send_pubkey_test debug2: we sent a publickey packet, wait for reply debug1: Authentications that can continue: publickey debug1: Trying private key: /home/me/.ssh/id_rsa debug3: no such identity: /home/me/.ssh/id_rsa: No such file or directory debug1: Trying private key: /home/me/.ssh/id_dsa debug3: no such identity: /home/me/.ssh/id_dsa: No such file or directory debug1: Trying private key: /home/me/.ssh/id_ecdsa debug3: no such identity: /home/me/.ssh/id_ecdsa: No such file or directory debug1: Trying private key: /home/me/.ssh/id_ed25519 debug3: no such identity: /home/me/.ssh/id_ed25519: No such file or directory debug2: we did not send a packet, disable method debug1: No more authentication methods to try. Permission denied (publickey).
注意:在发布之前,我试图清理主机,用户,地址等。 我可能做了一个转录错误。
我还validation了SSH_AUTH_SOCK在中介系统上的正确导出:
me@gateway:~$ echo $SSH_AUTH_SOCK # /tmp/ssh-X5p4HjmGhP/agent.918 me@private:~$ echo $SSH_AUTH_SOCK # /tmp/ssh-aR5WfnzmgE/agent.14429
我应该寻找什么来确定什么是错的?
你应该找的是在连接之后在中间系统上正确设置的SSH_AUTH_SOCK=环境variables。
确定后,您应该能够运行此命令并获得类似的结果。 如果你没有看到variables集,那么转发没有发生。
# export | grep SSH_AUTH declare -x SSH_AUTH_SOCK="/tmp/ssh-oDOTx6u2AR/agent.47026"
您的服务器必须允许转发,并且您的客户端必须configuration为使用转发。 服务器选项AllowAgentForwarding默认为yes ,但可以在您的服务器上禁用,如果它们已被强化。 在您的客户端上,您可以在连接期间使用-A ,或将ForwardAgent选项设置为yes 。 你不应该转发到不受信任的主机。 所以你可以在你的configuration中做这样的事情。
# where *.example.org is pattern that matches all the systems you trust # for forwarding purposes. Host *.example.org ForwardAgent yes
仔细看看你的日志,我可以看到你的客户正在提供密钥,目的地似乎不接受它。
debug2: key: me@me (0x5611e148efd0), ## your key from the agent debug2: key: /home/me/.ssh/id_rsa ((nil)), debug2: key: /home/me/.ssh/id_dsa ((nil)), debug2: key: /home/me/.ssh/id_ecdsa ((nil)), ... debug1: Offering RSA public key: me@me debug3: send_pubkey_test debug2: we sent a publickey packet, wait for reply debug1: Authentications that can continue: publickey
ssh-add -l将列出添加在你的ssh-agent中的密钥。
当你在命令行上input密钥名称时,你认为使用ssh-agent连接的是什么? 连接到第一个主机之前,运行
ssh-add my.key
那么你应该能够从第一跳连接到目标。