无法与 rsync 共享 ssh 连接

Ame*_*ina 5 ssh rsync

在我的.ssh/config文件中,我有以下内容:

Host xxx
User yyy
HostName zzzz
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p 
Run Code Online (Sandbox Code Playgroud)

这非常适合多路复用我的 ssh 连接(即登录一次,并与多个会话共享连接)。

我想将我的 ssh 连接与rsync多路复用(共享),以便我可以执行以下操作

rsync -arv -e ssh xxx:/source target
Run Code Online (Sandbox Code Playgroud)

并且不必通过rsync登录(我有 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
Run Code Online (Sandbox Code Playgroud)

slm*_*slm 5

我刚刚尝试过这件事,它对我有用。

注意:我还应该指出,在运行下面的命令之前,我运行了此命令,该命令在远程主机上设置用户帐户,以便与我的本地用户帐户的 ssh 凭据一起使用。

ssh-copy-id root@skinner
Run Code Online (Sandbox Code Playgroud)

我的设置如下:

$HOME/.ssh/config:

Host *
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
IdentityFile ~/.ssh/id_dsa

Host skinner mulder byers
    User root
Run Code Online (Sandbox Code Playgroud)

内容$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
Run Code Online (Sandbox Code Playgroud)

现在通过 ssh 连接到 Skinner 主机:

   初始 ssh 的 ss

内容$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
Run Code Online (Sandbox Code Playgroud)

发送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
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

上述 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
Run Code Online (Sandbox Code Playgroud)

发送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
Run Code Online (Sandbox Code Playgroud)

发送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
Run Code Online (Sandbox Code Playgroud)