Ubuntu – How to use rsync via ssh with rsa key passphrases


How can I use rsync with passphrases?
All googled "solutions" i found use passphrase-less keys which seems no real option.

i am runnning 2 ubuntu servers 12.04.2 LTS.

Best Answer

  • If you're using rsync with a regular user, ssh-agent may be what you are looking for.

    If ran into this problem while using rsync in a cron job. Cron jobs are run by the user cron in a restricted environement (some env var like SSH_AUTH_SOCK are missing, so ssh-agent does not work).

    A walkthrough is to use keychain. Keychain keeps ssh-agent environement variables in a file.
    So, first you install keychain.
    Then, you add these lines in your .bashrc, .zshrc or .profile file (tweak it to match your ssh keys):

    /usr/bin/keychain $HOME/.ssh/id_rsa
    source $HOME/.keychain/${HOSTNAME}-sh

    Additionnaly, to make cron jobs work, you can add this line at the beggining of your cron scripts:

    source $HOME/.keychain/${HOSTNAME}-sh

    More infos in this article : http://eli.thegreenplace.net/2013/10/08/some-notes-on-logging-and-ssh-access-from-cron-jobs/