![无法与 rsync 共享 ssh 连接](https://linux22.com/image/25643/%E6%97%A0%E6%B3%95%E4%B8%8E%20rsync%20%E5%85%B1%E4%BA%AB%20ssh%20%E8%BF%9E%E6%8E%A5.png)
在我的.ssh/config
文件中,我有以下内容:
Host xxx
User yyy
HostName zzzz
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
这对于多路复用我的 ssh 连接(即登录一次,并与多个会话共享连接)非常有用。
我想多路复用(共享)我的 ssh 连接同步,这样我就可以做类似的事情
rsync -arv -e ssh xxx:/source target
并且不必通过登录同步(我有 XXX 的双因素身份验证系统,如果我在使用 rsync 时可以跳过它,那就太好了)。
更新:我了解到默认情况下 rsync 会首先尝试重新使用连接。所以我不确定为什么它不起作用。这是我尝试的详细输出:
> rsync -arv -e 'ssh -v' XXX:~/file ~/temp/.
OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008
debug1: Reading configuration data /home/YYYY/.ssh/config
debug1: Applying options for XXX
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: auto-mux: Trying existing master
Control socket connect(/home/YYY/.ssh/XXX@ZZZZ:22): Connection refused
答案1
我刚刚尝试过这件事,它对我有用。
笔记:我还应该包括,在运行下面的命令之前,我运行了此命令,该命令在远程主机上设置用户帐户,以便与我的本地用户帐户的 ssh 凭据一起使用。
ssh-copy-id root@skinner
我的设置如下:
$HOME/.ssh/config
:
Host *
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
IdentityFile ~/.ssh/id_dsa
Host skinner mulder byers
User root
内容$HOME/.ssh/
:
$ ls -dl ~/.ssh
drwx------ 2 saml saml 4096 May 23 03:18 /home/saml/.ssh
$ ls -l ~/.ssh
total 16
-rw------- 1 saml saml 204 May 23 03:17 config
-rw------- 1 saml saml 736 Jan 10 2011 id_dsa
-rw-r--r-- 1 saml saml 612 Jan 10 2011 id_dsa.pub
-rw-r--r-- 1 saml saml 401 May 23 03:17 known_hosts
现在通过 ssh 连接到 Skinner 主机:
内容$HOME/.ssh/
:
$ ls -l ~/.ssh
total 16
-rw------- 1 saml saml 204 May 23 03:17 config
-rw------- 1 saml saml 736 Jan 10 2011 id_dsa
-rw-r--r-- 1 saml saml 612 Jan 10 2011 id_dsa.pub
-rw-r--r-- 1 saml saml 401 May 23 03:17 known_hosts
srw------- 1 saml saml 0 May 23 03:25 master-root@skinner:22
发送somefile.txt
到远程主机:
$ rsync -arv -e ssh somefile.txt skinner:~
sending incremental file list
somefile.txt
sent 106 bytes received 31 bytes 91.33 bytes/sec
total size is 13 speedup is 0.09
somefile.txt
从远程主机拉取:
$ rsync -arv -e ssh skinner:~/somefile.txt somefile-remote.txt
receiving incremental file list
somefile.txt
sent 30 bytes received 100 bytes 260.00 bytes/sec
total size is 13 speedup is 0.10
上述 rsync 命令的结果:
$ ls -l
total 8
-rw-rw-r-- 1 saml saml 13 May 23 03:19 somefile-remote.txt
-rw-rw-r-- 1 saml saml 13 May 23 03:19 somefile.txt
发送somefile.txt
到远程主机(-v):
$ rsync -arv -e 'ssh -v' somefile.txt skinner:~
OpenSSH_5.5p1, OpenSSL 1.0.0e-fips 6 Sep 2011
debug1: Reading configuration data /home/saml/.ssh/config
debug1: Applying options for *
debug1: Applying options for skinner
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: auto-mux: Trying existing master
debug1: mux_client_request_session: master session id: 5
sending incremental file list
somefile.txt
debug1: mux_client_request_session: master session id: 5
sent 106 bytes received 31 bytes 274.00 bytes/sec
total size is 13 speedup is 0.09
发送somefile.txt
到远程主机(-vv):
$ rsync -arv -e 'ssh -vv' somefile.txt skinner:~
OpenSSH_5.5p1, OpenSSL 1.0.0e-fips 6 Sep 2011
debug1: Reading configuration data /home/saml/.ssh/config
debug1: Applying options for *
debug1: Applying options for skinner
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: auto-mux: Trying existing master
debug2: fd 3 setting O_NONBLOCK
debug2: mux_client_hello_exchange: master version 4
debug1: mux_client_request_session: master session id: 5
sending incremental file list
somefile.txt
debug1: mux_client_request_session: master session id: 5
debug2: Received exit status from master 0
sent 106 bytes received 31 bytes 274.00 bytes/sec
total size is 13 speedup is 0.09
答案2
这可能是与您的 ssh 密钥的使用有关的问题吗?在远程服务器上,检查文件中的密钥authorized_keys
并验证您没有使用参数限制允许的使用command=
。有关文件格式的更多信息,请访问http://www.eng.cam.ac.uk/help/jpmg/ssh/authorized_keys_howto.html。