How to run restart mongod terminal commands without password prompt?

I want to run a command like sudo systemctl restart mongod in a script without it prompting for a password since the script wont be able to enter it.

I’ve been trying to edit the visudo file to allow specific commands to run without password prompt, but can’t seem to figure out exactly what setting I need to enter to get that to work.

Also there’s seems to be numerous ways to start/stop the mongo instance like: service mongod start, systemctl start mongod.service. I’m not sure what’s the difference between them.

Create admin access user inside linux machine change user group of file and

Change permission of file to root file excuteable

%dba ALL=(ALL) NOPASSWD: /bin/systemctl restart mongod

This entry would allow any member of the group dba to restart mongod.

All the supported Linuxes will be running systemd as the init system so I’d suggest just concern yourself with systemctl

1 Like

I have that entered in my visudo file, but it still prompts for password when I try to run the “systemctl restart mongod” command.

We’re way out of mongodb and into system administration. There are better sites and forums for that.

  • Check this use is in group_automation by using groups when logged in as that user.
  • Check the output of sudo -l when logged in as the users.