Some context:
- I have some services running on my Debian server, and from time to time I want to make a backup of the relevant data
- I have a
backupdirectory on the server, which I update manually by stopping the services, copying the data into that directory (usingrsync -Payz --delete --recursive, which preserves metadata and avoids unnecessary copies), then relaunching the services - I want to have a copy of the
backupdirectory on my laptop, and keep it updated - To that end, I want to run something like
rsync -Payz --delete --recursive user@server:backup . - The main difficulty here is that many of the files have
rootas an owner andrsyncisn't allowed to move them withoutsudo(the services run in containers, and those permissions make sense at the container level, but at the host level the system considers the host'srootis the owner) - To create the sever backup I can simply call
sudo rsync, but for the copy on my laptop I have to tellrsyncto runsudo rsyncon the server and forward the password request to the client, which brings us to the current issue
What I've done:
I've followed the advice from this post, so the full command I'm running is
rsync -Payz --delete --recursive -e "ssh -X" --rsync-path="sudo -A rsync" user@server:backup .
--rsync-path="sudo rsync"is used to runrsyncwithsudorights on the remote--rsync-path="sudo -A rsync"is used so thatsudorelies onssh-askpassto get the password-e "ssh -X"enables X11-Forwarding so thatssh-askpasscan ask me to type the password on my laptop
The issue
- This used to on my old laptop (a MacBook), but doesn't on my new one (running a Manjaro distribution). Given that the linked post's comments say it's working on Ubuntu, I'm assuming I need to change something in my configuration, or maybe I'm missing a dependency or something, but I have no idea what or why
- The error I get is the following:
Error: Can't open display:
sudo: no password was provided
sudo: a password is required
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(231) [Receiver=3.2.7]
- When I run the command with
-e "ssh -Xv", the following lines appear that seem to be the issue
debug1: X11 forwarding requested but DISPLAY not set
debug1: Sending command: sudo -A rsync --server --sender -logDtprze.iLsfxCIvu . backup
Error: Can't open display:
sudo: no password was provided
sudo: a password is required
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [email protected] reply 0
debug1: channel 0: free: client-session, nchannels 1
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
Transferred: sent 2176, received 2464 bytes, in 0.2 seconds
Bytes per second: sent 9432.6, received 10681.1
rsync error: error in rsync protocol data stream (code 12) at io.c(231) [Receiver=3.2.7]
so apparently when rsync runs ssh -X here, the DISPLAY variable is left unset
- If I run
ssh -X 'echo $DISPLAYhowever, it does displayslocalhost:10.0, and runningssh -X user@server 'sudo ls'does ask me the password as expected (through a window titled "OpenSSH Authentification Passhrase Request") - I believe that means that the problem is in the interaction between
ssh -Xandrsync, not the X11-Forwarding itself, but I don't get what I'm doing wrong
I can only suggest you trace the environment being passed through rsync as follows. Add option
-nto do no transfers, and use some/tmp/dummyfile. Prefix the command withstraceusing option-vto see the environment duringexecve()calls,-fto follow children, and-o logto output to some log file. For example,Looking through the log file you should see something like
(one long line). Beware, you may need to ignore many execve's of
sshthat are attempted and fail as each directory in the currentPATHis tried. In this example output, 5261 is the process id.The
execve()system call of/usr/bin/sshshows the arguments tosshin the first array[...], and the environment passed to the command in the second array[..."DISPLAY=:0"...]. Ensure "DISPLAY=:0" is in this second array.If it isn't, then look earlier in the file for the first
execve()ofrsyncto see if DISPLAY is in the env there. You should find something like:You can add a second
-ftostraceto get separate log files, one for each process, rather than all intermixed.If it is in the first
execve("/usr/bin/rsync", and not in the laterexecve("/usr/bin/ssh", that would indeed suggest that rsync has deliberately removed it from the environment. Perhaps this is some sort of new security feature?To work round it, create your own shell script "ssh" in your
PATHthat simply does