Wednesday, February 17, 2021

rsync, screen and ssh-agent

On some of our other Ubuntu servers, rsync in a cron job as root works fine with ssh and key-based authentication. But not on a CentOS server I recently logged on to, because ssh-agent was not automatically started on login.

So, I have to run the following - 

eval `ssh-agent -s` 
ssh-add /path/to/keyfile.pem

and then do the ssh -i keyfile user@remoteserver

If I want to run a long rsync job from within screen, I need to run the above commands again from within screen, or else the ssh-agent is not accessible from within screen.

The next issue was the use of rsync with directories which had spaces in them. Instead of laboriously escaping each space with a backslash, I used the --protect-args method.

rsync -azvhrt --protect-args -e ssh  "/local path/with spaces/directory to copy" "user@remotemachine.tld:/remote/path/with spaces/"

No comments:

Post a Comment