0

Problem

I have the following scenario:

  • motion is creating directories and files with the user:group motion:motion and the permissions 755
  • as a cron task, I'd like to periodically copy these files to a remote computer and then delete them. The command I'm trying to use is

    sudo rsync -avz --remove-source-files /home/pi/Pictures/SecurityCamera/ username@host:/Users/username/Pictures/SecurityCamera

  • The files are successfully copied to the remote machine, however without the sudo, the local files aren't deleted. With the sudo, I'm required to enter my password for the remote machine, even though I've set up public key authentication.


Attempted Solutions

I've tried changing a few settings in the remote sshd_config to no avail

PermitRootLogin without-password 
StrictModes no 

I've also tried adding the both the pi and root user to the motion group, but looking more closely at the permissions, groups don't have write access to the files I'm moving.


TL;DR

How can I use sudo rsync to delete local files created by another user without entering a password for the remote machine?

0

It looks to me that you doing this on Raspberry Pi.

  1. Add this string pi ALL=(ALL) NOPASSWD: ALL to the /etc/sudoers
  2. Add user pi to the group motion: usermod -a -G motion pi
  3. Change directory permission where motion saving files to 775 (chmod -R 775 /path/to/motion/dir) You can use now sudo rsync without providing a password but keep in a save place credentials for user 'pi' since it almost a root now

P.S. Another way is to allow user motion to be a normal user by assigning a password and shell to him sudo usermod -s /bin/sh motion; sudo passwd motion This way you can login for rsyncing as a user motion

P.P.S Following comment, what actually you need is:

echo '*/5 * * * * root /usr/bin/rsync -avz --remove-source-files /home/pi/Pictures/SecurityCamera/ username@host:/Users/username/Pictures/SecurityCamera' | sudo /usr/bin/tee /etc/cron.d/saveMotionPics.task

3
  • I'm calling rsync as a cron task. Aren't cron tasks always run as root? Jan 7 '17 at 18:12
  • Not really, if you using system cron then you need to specify user - who is going to run some program, kinda like that */5 * * * * motion /pat/to/the/program/to/run.sh where motion is a user who will actually run.sh P.S. of cause you can use root instead of motion - this way you dont need any sudo
    – Alex
    Jan 7 '17 at 18:27
  • I added right cron job to my answer after P.P.S. Just correct how often you want rsyncing, i set there every 5 minutes
    – Alex
    Jan 7 '17 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.