I was reading the script /etc/init.d/sudo. It has been written as a comment in the script that it provides limited super user privileges to specific users.

Though, I could not understand the script as to how is it working? Can someone explain me the script?

I am using Ubuntu 14.04 32-bit.


init files, which run at system boot (or on demand) do two main things:

  • they start daemons running
  • they do various one-time-per-boot tasks, such as cleaning up or preparing files, setting network parameters, etc.

In this case, the sudo init script does not start a daemon. Instead, it invalidates any cached credential files that may have been left around when the system last shut down. It does this by using touch to set their modification time to a very long time ago (0, which is Jan 1, 1970).

case "$1" in
        # make sure privileges don't persist across reboots
        if [ -d /var/lib/sudo ]
                find /var/lib/sudo -exec touch -d @0 '{}' \;

Scripts in /etc/init.d are there to allow the starting and stopping of services by systemd and similar init systems. They have a specific format and are what is actually called when you do something like

service sudo stop

So, the script you mention is simply a wrapper that can start or stop the sudo service. For more details, I suggest you read up on Linux init scripts.

  • I think the OP is asking about the sudo mechanism as opposed to init.d scripts. – mkc Sep 8 '14 at 16:28
  • 1
    @Ketan I suspect so too but that's not what the actual question is saying. – terdon Sep 8 '14 at 16:29
  • 1
    The sudo daemon??? Where did you find that beast? – guntbert Sep 8 '14 at 20:43
  • @guntbert 'tis in a land far away and lost in time and only the bravest of knights may find it. It has also been removed from this answer. – terdon Sep 8 '14 at 21:20
  • ah good - I was really scared at the thought having lived next to it for a long time and having it frequently but inadvertently invoked :-) – guntbert Sep 9 '14 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.