How can I configure a cron job to run as a non-root user? I want to schedule a task using cron, but I don’t want to run it with root privileges. What steps must I take to set up a cron job that runs as a specific non-root user?
You can log in as a non-root user and then use the crontab -e command to edit the user’s crontab file. This will open crontab, especially for logged-in users. Then you can put any task will perform under that user.
Method 2 :
You can add -u <username> with crontab -e command which will also open the crontab to the user.
Method 3:
Before the scheduled task command, you can define the username. It will also run the task as that user.
For example.