Score:1

Allowing a sudo command to run without needing password

us flag

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?

muru avatar
us flag
Where in `sudoers` did you put this? Edit your post to add the output of `sudo -l`, please.
Askerman avatar
us flag
@muru i added the output
muru avatar
us flag
@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.
Askerman avatar
us flag
@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?
NotTheDr01ds avatar
vn flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.