3

I want to have a scheduled crontab run on a daily basis but not as the root user.
Reasons being that this is a simple backup and cleanup job and I don't want any accidents.
The backup folder will have permissions for user 'mysql-backup' (for example) and I want the crontab to only run as user mysql-backup. Obviously I don't want the mysql-backup user logged in or anything like that for the crontab to work.

4 Answers 4

6

You can either edit the desired user's crontab:

crontab -e -u mysql-backup

or use su or sudo to change to that user at runtime in root's crontab.

2

run sudo crontab -u <user> -e.

1

If you're root, you can just su to the user, and create a crontab.

That should work.

Something like this should work fine.

su kyle -c "crontab -e"

whistles to himself

crontab -u kyle -e

Obviously that's what I meant.

Since it wasn't explicitly answered, a user does not have to be a normal user, or have login rights, or anything like that to have a working crontab.

0

For system crontab, /etc/crontab, the 6th field is the user. For the crontab used by the user run crontab -e as that user and edit it's crontab. The crontab for users is stored in /var/spool/cron/<username>

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.