rsyncing as root when root login is disabled?

Matt McCutchen hashproduct+rsync at gmail.com
Sat Sep 16 22:07:54 GMT 2006


On 9/16/06, Joe Ruby <joeat303 at yahoo.com> wrote:
> I tried again:
>
> $ rsync -av --progress --rsync-path='sudo
> /usr/bin/rsync' admin at mydomain.com:/backup/var var
> Password:12345
>
> rsync: connection unexpectedly closed (0 bytes
> received so far) [receiver]
> rsync error: error in rsync protocol data stream (code
> 12) at /SourceCache/rsync/rsync-24/rsync/io.c(359)
> $ 12345
> -bash: 12345: command not found

Wayne beat me to this, but to elaborate:

The trouble is that the standard input and output of sudo are
connected to the standard input and output of the local rsync, not to
your terminal.  I'm guessing the "Password" prompt you see is that of
SSH.  Then sudo sends its own password prompt down the tunnel to the
local rsync, which gets confused because "Password:" isn't part of the
rsync protocol.

The correct solution is to use a program such as "expect" to connect
the SSH tunnel to the terminal for the sudo prompt and then to the
local rsync for the transfer.  Alternatively, depending on how sudo
handles terminals (I don't know the details), you might be able to
establish a sudo timestamp with "ssh admin at mydomain.com sudo -v" and
then run rsync without needing a sudo password.

Matt


More information about the rsync mailing list