0

On Ubuntu I want to set up cron task to send email from my application. I think that I should run this crontab as user, not as root. Am I right? But I cannot go to the crontabs directory. I have permission denied.

user1@srv:/var/spool/cron$ cd crontabs
-bash: cd: crontabs: Permission denied
user1@srv:/var/spool/cron$ ls -al
total 12
drwxr-xr-x 3 root root    4096 Nov 26  2016 .
drwxr-xr-x 6 root root    4096 Nov 26  2016 ..
drwx-wx--T 2 root crontab 4096 Feb 17 19:01 crontabs

When I have called command crontab -e as user1, it has been written in tmp folder. So should I run this task as user1? And if I should, how to do that?

1 Answer 1

2

You didn't tell us the exact command you want to put in the crontab, so it's hard to tell definitely if it should be in the user's crontab.

Permission denied is expected. Nothing to worry about.

In general running crontab -e as unprivileged user is OK. The tool lets you edit a temporary copy and (after you save it without changing its temporary name or path) installs it safely in the right directory. The tool holds the setgid flag and belongs to the group crontab. This way it can access the directory you cannot access directly.

4
  • It will be correct if I run crontab as root ?
    – Robert
    Feb 18, 2020 at 19:11
  • @Robert You didn't tell us the exact command you want to put in the crontab, so it's hard to tell definitely if it should be in the user's crontab or root's crontab. Feb 18, 2020 at 19:13
  • I want to run action in PHP Laravel: localhost/sendemail
    – Robert
    Feb 18, 2020 at 19:27
  • @Robert I know nothing about it. But if you can craft a command that does what you want while run by unprivileged user then there is no reason to escalate privileges and involve root in it. Put the command in the user's crontab. Feb 18, 2020 at 19:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .