Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automate rsync without asking for password prompt [closed]

Tags:

ssh

rsync

I would like to automate the rsync task as a cron job. Since it needs the passphrase I am not able to do the cronjob. I need to specify the passphrase along with the rsync command or I will store the passphrase in a file and I will read from it. My command will look like this:

rsync -aPe "ssh -i ' . $server->{'ssh_key'} . '" ' . $server_lock_dir;

So where do I put the password ?

like image 908
Rijosh K Avatar asked Apr 21 '10 09:04

Rijosh K


2 Answers

You don't need to do that - just need to set up a pair of ssh keys and put the public key in the remote system's .ssh directory.

Then you just do this:

rsync -a -e ssh /local/path/ server:/remote/path/

(Note that -e ssh has been the default for quite a few years now, so you can probably omit it, unless you're using a very old version.)

There's a "how to" guide on setting up the keys here.

like image 85
Paul R Avatar answered Oct 13 '22 22:10

Paul R


If you want this to work from cron, you have several possibilities:

  • setup password-less ssh keys - not very secure
  • setup password-less ssh keys, but combine them with ssh ForceCommand in the authorized_keys file to limit the commands that can be run with that ssh key. See man sshd, google on "ssh ForceCommand"
  • setup passworded ssh keys, but combine them with keychain to keep the key in memory between sessions. I've written a blog post on this: ssh, ssh-agent, keychain and cron notes
like image 25
Sonia Hamilton Avatar answered Oct 14 '22 00:10

Sonia Hamilton