I am using rsync to copy files to a target server when I connect to it using ssh. To do this I have the following in my ssh config file:-
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
...
...
host dns
LocalCommand rsync --update -a -e "ssh -o PermitLocalCommand=no" ~/.cfg/ dns:.cfg/ &
...
...
The ControlMaster bit means that after one ssh to the server subsequent ssh connections don't ask for the password. Thus the rsync runs without asking for the password.
The oddity is that it won't work without the & at the end of the LocalCommand line in the config file. Why does it need this? Without the & the login just hangs after entering the password and if you CTRL/C it you get an rsync error as it's been interrupted by the CTRL/C and the connection fails. The rsync copy only takes a fraction of a second, the hang is not due to rsync taking a long time.
I took quite a while to find how to make this work, initially without the & it just hung, as I said. I then put the rsync command in a script and called that, it still hung. I found that starting a terminal from the script and running the rsync in that worked OK. Then I went backwards and put the & after the rsync in the script and that worked, finally I got to what I have above.
It's not a big issue, I'm happy with the way it works, but I'd love to kow why the & is needed.
This is all on Linux, both ends running xubuntu/ubuntu.
Best Answer
Possibly answer in this blogpost:
I've solved similar problem by adding -S none to list ssh options: