0

Hi there is a bunch of videos and resources on how to rsync locally rsync /home/user1 /home/user2/backup, but i haven't found any tutorials on rsync crontab to another server

pretty much, i use crontab -e and i have a script i run from rsynch.sh

#!/bin/bash
rsync -xza /home/willchap  willchap@server02:/home/willchap/backup

it will work fine without crontab, the problem is, i am guessing crontab fails because it is asking for a password

what are my options here?

1

2 Answers 2

4

The best option, if you can, is to set up key-based SSH authentication on the remote server, and use a key with no passphrase on the client. This will allow the SSH connection, which rsync uses when you use that [user@]server:path notation, to happen without prompting for a password.

Ubuntu documentation for doing this is at:

https://help.ubuntu.com/community/SSH/OpenSSH/Keys#Key-Based_SSH_Logins

Once set up, try to SSH to the remote server from and to the same accounts that rsync would use, and see if it asks for a password. If it doesn't, it's set up correctly.

2
  • If you refer to this Q&A, askubuntu.com/questions/939677/…, it turns out that in addition to setting this up it is also necessary to explicitly send the public key with the actual rsync command, also.
    – SDsolar
    Jul 26, 2017 at 21:10
  • As part of the setup, you place the public key of the client into the authorized_keys file on the server, but this is a one-time operation only, after which rsync over SSH will just work as normal without prompting for a password. Jul 27, 2017 at 0:27
0

actually, yes it is possible.

do your normal rsyncscript.sh you will need to generate keys using the command ssh-keygen

in your home directory, go to .ssh/id_rsa.pub and copy that into the other servers /authorized_keys file

1
  • While your answer is technically correct, it would be better if you could flesh it out and show the steps: ssh-keygen, ssh-copy-id -i ~/.ssh.id_rsa.pub <target> and all that. It is just a two-step process for each system.
    – SDsolar
    Jul 26, 2017 at 8:53

Not the answer you're looking for? Browse other questions tagged .