1

I have the following command:

sudo service cron start

When I type it into the terminal, it asks me for a password, just as it should. But I need for users (or if all users aren't possible, then at least my user) to be able to run this specific command without needing to put in any passwords. I googled around, even looked at similar questions here and found about visudo, so I gave it a try, and put this into the sudo config file, which I accessed through visudo.

mike ALL = NOPASSWD: /usr/sbin/service cron start

But it had no effect at all, I still get asked for a password when I try to do sudo service cron start, or even sudo /usr/sbin/service cron start

sudo -l:

Matching Defaults entries for mike on bolt:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User mike may run the following commands on bolt:
    (root) NOPASSWD: /usr/sbin/service cron start
    (ALL : ALL) ALL

So what am I doing wrong here?

Askerman
  • 816
  • 3
  • 14
  • 24
  • Where in `sudoers` did you put this? Edit your post to add the output of `sudo -l`, please. – muru Jul 29 '21 at 08:21
  • @muru i added the output – Askerman Jul 29 '21 at 08:24
  • 3
    @Askerman add your rule at the very end of the `sudoers` file. You can see a later rule (`(ALL : ALL) ALL`) is getting precedence here. – muru Jul 29 '21 at 08:51
  • @muru yes that was it! if you add your comment as answer i will accept it, one more thing, how would the command look to allow all users to execute this command? – Askerman Jul 29 '21 at 09:02
  • You have this tagged as *windows-subsystem-for-linux*, but (a) your question doesn't mention it at all, and (b) it's not normal to have multiple users in a WSL configuration. Are you really running this system under Windows 10 with WSL, or is that tag a mistake? There's another solution for running `root`-level commands without a password in WSL that most "normal" Ubuntu users wouldn't know about. – NotTheDr01ds Jul 29 '21 at 14:55

0 Answers0