Running cron under sudo

Erik Christiansen dvalin at internode.on.net
Wed Oct 8 11:06:43 UTC 2008


On Tue, Oct 07, 2008 at 02:42:09PM -0400, Brian McKee wrote:
> On Tue, Oct 7, 2008 at 12:56 PM, Derek Broughton <news at pointerstop.ca> wrote:
> >> Nope
> >>   sudo su -
> >> will log you in as root after you provide YOUR password.
> >
> > No, he's right.  The "proper" way to get a root user shell is "sudo -i".
> 
> I'm not sure about that.  I've read both man pages, and I'm not sure
> there's a difference.  I think you end up in the same place so to
> speak.  Unless someone proves me wrong it's a habit I'm keeping :-)

Aha, one of the all too few posts on this list to gently remind that there's
more than one way through the forest. Your way is fine, and equivalent,
in my experience.

All EOUUs (Extremely Orthodox Ubuntu Users) please blink for just one
paragraph. Since the OP wanted to change root's crontab, I would have
just used "su -" and root's password on my ubuntu box. If we're running
a root crontab, then we might as well have a proper root account, to be
consistent.

If "sudo su -" <user_passwd> didn't do the same as "su -" <root_passwd>
does when the root account is enabled, then sudo would be broken.

> 
> >> Then crontab -e will work as expected.
> > Not according to man crontab(1).
> 
> Yeah I know - I even quoted that section in my reply.   After
> re-reading it, you are probably right on this one.  I always read that
> as 'if you use su -c crontab -e' it might not work', but your
> interpretation could very well be the correct one.
> 
> All that said - I tested it my way and it worked :-)  So that's the
> way I recommended it....

Even with sudo, it pretty much has to work in the expected way, as you
say, given:

erik at ratatosk:~$ sudo su -
root at ratatosk:~# id -a
uid=0(root) gid=0(root) groups=0(root)
root at ratatosk:~# pwd
/root
root at ratatosk:~# crontab -e
no crontab for root - using an empty one
No modification made

On a machine where explicit limitations have been imposed in
/etc/sudoers, the "su -" can explicitly be made to fail, but that's
self-imposed. (Just to cut any red herrings off at the pass. :-)

Erik




More information about the ubuntu-users mailing list