Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In my .ssh/config file I have the following:

Host xxx
User yyy
HostName zzzz
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p 

This works great for multiplexing my ssh connections (i.e. login once, and share the connection with multiple sessions).

I would like to multiplex (share) my ssh connection with rsync, so that I can do things like

rsync -arv -e ssh xxx:/source target

and not have to login through rsync (I have two-factor authentication system with XXX and it would be great if I can just skip that when I use rsync).

Update: I learn that by default rsync would try to re-use the connection first. So I am not sure why it isn't working. Here is the verbose output of my attempt:

> 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
share|improve this question
2  
This should be working. Maybe try -e 'ssh -v' to see if rsync over ssh is indeed looking for the ControlMaster socket? –  jw013 Sep 19 '12 at 18:28
    
Thanks! @jw013 I have updated my post. –  user815423426 Sep 19 '12 at 18:52
    
And yet, plain ssh not invoked by rsync works? –  jw013 Sep 19 '12 at 19:00
    
Ì guess the space in Control master auto (rather than ControlMaster) is not contained in the config? –  artistoex Sep 19 '12 at 19:03
1  
Is your home directory on NFS? I'm not sure how FIFOs behave there. Maybe trying setting ControlPath to /tmp/$USER.ssh/%r@%h:%p (with the appropriate permissions). –  Chris W. May 23 '13 at 3:47
show 12 more comments

2 Answers

up vote 1 down vote accepted

I just tried this exact thing and it worked for me.

NOTE: I should also include that prior to running the commands below I ran this command, which sets up the user account on the remote host for use with my local user account's ssh credentials.

ssh-copy-id root@skinner

My setup is as follows:

$HOME/.ssh/config:

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

Host skinner mulder byers
    User root

contents of $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

Now ssh to host skinner:

   ss of initial ssh

contents of $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

send somefile.txt to remote host:

$ 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

pull somefile.txt from remote host:

$ 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

results of above rsync commands:

$ 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

send somefile.txt to remote host (-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

send somefile.txt to remote host (-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
share|improve this answer
add comment

Might it be a problem related to the usage of your ssh key? On the remote server, check your key in the authorized_keys file and verify that you did not limited the allowed usage with the command= parameter. More information on the file format is available at http://www.eng.cam.ac.uk/help/jpmg/ssh/authorized_keys_howto.html .

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.