68
7
I would like to run a cron job as a specific user on my machine. How may I specify the user for a cron job to run as?.
The cron jobs will be running on a server (running on Ubuntu 10.0.4). The 'users' are users that have been created specifically for carrying out specific server side tasks. These 'users' have the following in common:
- Cannot log onto the system
- Have restricted access to specific folders/files
I think this is the correct answer. I will have to look for some examples and investigate some more. – morpheous – 2010-08-02T12:19:25.217
2Plus one from me, this is the best way to do what you want. More precisely look in /etc/crontab file and you will see, that after the time template and before the command there is "root" written there. This means that "root" runs those commands. Just add your own schedule and instead of "root" use any user. Also, note that if you use per user crontabs (as sugested by Eric D) you may loose the functionality of the system wide crontab (/etc/crontab and /etc/cron.d). – Patkos Csaba – 2010-08-02T12:25:16.727
3The preferably solution I guess would be to just
crontab -u <user> -e
to keep everything in one place, which you can do as root. I like to group my cron jobs by function, though, instead of just by user, so this is the preferable solution for me. – Stuart H – 2017-09-05T10:46:10.927