I use a command to transfer files with rsync and a ssh key:
sudo rsync -P -e 'ssh -i <absolute path to keyfile>' <file> user@<server>
I need the first sudo because the file I'm copying is owned by root or other users.It worked fine for the last few months, but about two weeks ago I got a connetion refused from the keyfile (it has 600 permissions, but is owned by the user using this command). The exact error message is:
<IP address>
ssh: connect to host <IP address> port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.2]
I found out that it now works with a second sudo in front of the ssh command:
sudo rsync -P -e 'sudo ssh -i <absolute path to keyfile>' <file> user@<server>
But I don't understand why all of the sudden this changed and I could not find anything about this. Why do I suddenly need a second sudo for this to work? My guess is that the ssh command inside ' ' cannot access the keyfile despite the whole command running with sudo, but as mentioned before it worked until about two weeks ago. My goal until now was to not use sudo at all, but I am not sure how to achieve this now.