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.
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/
I found the perfect answer to this on https://stackoverflow.com/questions/3299951/how-to-pass-password-for-rsync-ssh-command
It worked perfect for me. It is a security risk as kainjow says, but it solves the problem.
Answer by kainjow:
If you can't use a public/private keys, you can use expect:
#!/usr/bin/expect
spawn rsync SRC DEST
expect "password:"
send "PASS\n"
expect eof
if [catch wait] {
puts "rsync failed"
exit 1
}
exit 0
You will need to replace SRC and DEST with your normal rsync source and destination parameters, and replace PASS with your password. Just make sure this file is stored securely!
I guess all you want is the '-e' parameter for rsync to use a ssh connection, which automaticly asks for your passphrase...
rsync -avze ssh /home/user remoteuser@example.com:/backups
This would copy /home/user from your local computer to your remote computers /backups directory