我们有以下的SSH跳转设置:
localhost -> hub -> server
hubuser @ hub接受localuser @ localhost的公钥。
serveruser @ server接受hubuser @ hub的公钥。
所以我们发出ssh -t hubuser@hub ssh serveruser@server来连接服务器。
这个设置的问题是我们不能直接到服务器。
我尝试创build.ssh / config文件,如下所示:
Host server user serveruser port 22 hostname server ProxyCommand ssh -q hubuser@hub 'nc %h %p'
但我无法连接(yigit是localuser):
$ ssh serveruser@server -v OpenSSH_6.1p1, OpenSSL 1.0.1c 10 May 2012 debug1: Reading configuration data /home/yigit/.ssh/config debug1: /home/yigit/.ssh/config line 19: Applying options for server debug1: Reading configuration data /etc/ssh/ssh_config debug1: Executing proxy command: exec ssh -q hubuser@hub 'nc server 22' debug1: permanently_drop_suid: 1000 debug1: identity file /home/yigit/.ssh/id_rsa type 1000 debug1: identity file /home/yigit/.ssh/id_rsa-cert type -1 debug1: identity file /home/yigit/.ssh/id_dsa type -1 debug1: identity file /home/yigit/.ssh/id_dsa-cert type -1 debug1: identity file /home/yigit/.ssh/id_ecdsa type -1 debug1: identity file /home/yigit/.ssh/id_ecdsa-cert type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1 debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH_5* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_6.1 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: sending SSH2_MSG_KEX_ECDH_INIT debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: Server host key: ECDSA cb:ee:1f:78:82:1e:b4:39:c6:67:6f:4d:b4:01:f2:9f debug1: Host 'server' is known and matches the ECDSA host key. debug1: Found key in /home/yigit/.ssh/known_hosts:33 debug1: ssh_ecdsa_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: /home/yigit/.ssh/id_rsa debug1: Authentications that can continue: publickey debug1: Trying private key: /home/yigit/.ssh/id_dsa debug1: Trying private key: /home/yigit/.ssh/id_ecdsa debug1: No more authentication methods to try. Permission denied (publickey).
请注意,它试图使用公钥localuser @ localhost在服务器上进行身份validation,并且因为它不是正确的而失败。 是否可以修改ProxyCommand以便hubuser @ hub的密钥用于在服务器上进行身份validation?
您可以在ProxyCommand使用-i指定用于从localhost到hub的连接的密钥文件。 您可以使用IdentityFile指定用于从localhost连接到server的密钥文件
这两个密钥文件都需要位于localhost 。 这个设置将不需要两个密钥文件中的任何一个位于hub 。
确保你的本地机器(也可能是所有其他服务器)上安装了netcat软件包,例如在Ubuntu上,你可以使用sudo apt-get install netcat 。
确保跳转服务器可以不通过密码SSH连接到目标服务器(例如:使用ssh-copy-id )
在本地机器上添加〜/ .ssh / config:
Host any-nickname-here User destination-user ProxyCommand ssh -o 'ForwardAgent=yes' user@hop-server 'ssh-add && nc destination-host destination-port'
然后下面应该工作ssh any-nickname-here或者scp file.txt any-nickname-here:/dir/path/