Running Cron Jobs as a Specific User
The cleanest way to run a job as a given user is to edit that user's crontab: crontab -u username -e. System crontabs in /etc/crontab and /etc/cron.d also have a user field. Avoid running everything as root when a limited account will do.
Per-user crontab (recommended)
Edit another account's crontab as root:
sudo crontab -u www-data -e
Jobs there run as www-data. List them with crontab -u www-data -l.
System crontab with a user field
In /etc/crontab and files under /etc/cron.d/, add the user before the command:
0 3 * * * deploy /opt/app/deploy.sh
From root, drop privileges inline
If a job lives in root's crontab but must run as another user:
0 3 * * * su -s /bin/sh -c '/opt/app/run.sh' appuser
FAQ
How do I run a cron job as another user?
Use sudo crontab -u username -e to edit that user's crontab. Every job there runs as that user.
Where is the user field in a cron entry?
Only system crontabs (/etc/crontab and /etc/cron.d/*) have a user field, placed after the five time fields and before the command. Per-user crontabs do not.
Should cron jobs run as root?
Prefer a limited account. Run each job under the least-privileged user that can do the work to limit damage if the script is compromised.