0

Hi I am trying to backup an ubuntu 16.04 server to a freeNAS backup server using rsync and crontab.

The command I am using for rsync is

sudo rsync --delete --delete-excluded -az /home/backups/ [email protected]:/mnt/backupvol/production_nfs/db-server-master/

When I run this command from command line first it asks for sudo password then root password for 192.168.1.6. Then command is executed as expected.

when I try to sudo ssh [email protected] then also it asked for both passwords. I have tried to use sudo ssh-copy-id [email protected] and have copied the keys successfully.

My question is

  1. How do I bypass password entry
  2. when I run rsync command with crontab I am getting wrong password errors

How do I correct these?

1 Answer 1

1

First, do Not try to use sudo in a cron job. sudo has nowhere to prompt for the password.

Run your command in root's crontab - the /etc/crontab file. Edit this file directly, Not with sudo crontab -e. The /etc/crontab file has a non-standard format, so read the comments at the front of the file carefully.

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.
1
  • 1
    What's wrong with sudo crontab -e? That actually edits root's crontab whereas /etc/crontab is the system-wide crontab.
    – PerlDuck
    Mar 11, 2018 at 8:49

You must log in to answer this question.

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