Skip to content

Instantly share code, notes, and snippets.

@kai101
Last active February 13, 2018 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kai101/10e7910389a750bdb2ffcd53bcdda2dc to your computer and use it in GitHub Desktop.
Save kai101/10e7910389a750bdb2ffcd53bcdda2dc to your computer and use it in GitHub Desktop.
Rsync over shared connection.

Yes, see the ControlMaster and ControlPath options.

You can start the master connection with:

mkdir ~/.ssh/ctl
ssh -nNf -o ControlMaster=yes -o ControlPath="$HOME/.ssh/ctl/%L-%r@%h:%p" user@host

And then use rsync with:

rsync -e "ssh -o 'ControlPath=$HOME/.ssh/ctl/%L-%r@%h:%p'" ...

Then

ssh -O exit -o ControlPath="$HOME/.ssh/ctl/%L-%r@%h:%p" user@host

to terminate the master connection.

(And by the way, some versions of ubuntu have an annoying feature in that they rebuild /etc/motd upon every login (including non-interactive ssh sessions), which can take a long time if part of that involves checking if updates are available for instance. IIRC, you can disable it by removing pam_motd from your pam configuration)

It should be noted that OpenSSH client also supports the -M command-line option whith the same meaning as -o ControlMaster=yes and the -S <path> command-line option with the same meaning as -o ControlPath=<path>. At least this is the case with OpenSSH 5.1p1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment