How to use rsync via ssh with rsa key passphrases?
Solution 1
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/
Solution 2
rsync -Pavp --rsh="ssh -i YOUR_KEY" DEST USER@REMOTE:SOURCE
Related videos on Youtube
Pascal
Updated on September 18, 2022Comments
-
Pascal almost 2 years
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.
-
amc almost 11 yearsto provide a complete answer, please summarize the steps rather than simply providing a link.
-
FrankM almost 11 yearsI don't think I could explain it any better than the link provided. But if there is anything unclear I can explain it.
-
Pascal almost 11 yearsi appreacite your attempt frankm, however you completely missed my question. the link is a nice resource - but not for my question. i am looking for a secure solution using passphrases.
-
Pascal almost 11 years@amc allow me to "clarify" my question by quoting it: "How can I use rsync with passPHRASES?"
-
amc almost 11 years@Pascal that doesn't help. Lose the attitude please -- people on this site are volunteering their time and expertise to help. Since there are two ways to use pass phrases I am seeking clarification to find out which method you had in mind.
-
Pascal almost 11 years'help' is a good thing, with reading too. my question is crystal-clear IMHO. therefore I point everyone to my original question. this helps contributors with off-topic responses concerning pass_words_ to improve the quality of responses. had I added any redundant information to my question, not only would the quality of the question have decreased, it would also have sent a false feedback to those who didn't pick up the unambiguous (IMHO) term ( pass___phrases___ which is featured both in the title and text! if my question is unclear, just point out why instead of being oversensitive.
-
Pascal almost 11 years" I am seeking clarification to find out which method you had in mind" none. i am not aware of any methods. my suggestion to you would be naming those 2 methods (unless they deal with pass_words_) - it's puzzling me that you didn't.
-
FrankM almost 10 yearsI 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 [email protected]:/backups
This would copy /home/user from your local computer to your remote computers /backups directory -
Fabby over 8 yearsI'm sorry, but the edit came in quite late, so 2 other users voted to delete as well, so it took me some time to have it undeleted (but now you've got 2 updates upvote as well)
-
Jack Wasey about 7 yearsThis also enables
ssh -oBatchMode=yes ...
so a script will fail instead of prompting and waiting for ever -
Guilherme Corrêa Peralta almost 7 yearsThis also works using a private key, in my case I had to replace {"password:"} to {"'name_if_my_private_key_file':"} because that's what the script has to look for after running the rsync command.