Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set cronjob with non-root user?

Error : crontab: must be suid to work properly

I want to set cronjob in docker container with non-root user. Is it possible to set a cron without using sudo and without installing cron? I am using alpine docker container.

like image 595
LazyCoder Avatar asked Dec 06 '17 06:12

LazyCoder


3 Answers

/etc/crontab is the system wide crontab.

The format of /etc/crontab is like this:

# m h dom mon dow user      command
*   *  *   *   *  someuser  echo 'foo'

while crontab -e is per user, it's worth mentioning with no -u argument the crontab command goes to the current users crontab. You can do crontab -e -u <username> to edit a specific users crontab.

Notice in a per user crontab there is no 'user' field.

# m h  dom mon dow  command
*   *   *   *   *   echo 'foo'

An aspect of crontabs that may be confusing is that root also has its own crontab. e.g. crontab -e -u root will not edit /etc/crontab

See Configuring cron for more information: https://www.freebsd.org/doc/handbook/configtuning-cron.html

In most Linux distros, per user crontabs are typically stored in: /var/spool/cron/crontabs/<username>

like image 115
Allan Avatar answered Oct 02 '22 23:10

Allan


Yes you can run its own, cron in specific user without sudo, As each user will be having the crontab file no need to install it explicitly. to run crontab of any user, use -u option , please note that user must be privileged to use -u

 $ crontab -u <username> -e
like image 29
sanath meti Avatar answered Oct 02 '22 22:10

sanath meti


I solve it adding the name of the user we need to execute cron jobs in the file /etc/cron.allow. If this files does not exists you have to create it. More details about cron.allow file

like image 39
Aurelio Vivas Avatar answered Oct 02 '22 22:10

Aurelio Vivas