1

What is the best way to grant user an access so they can restart the nagios services?

I have added in visudo

USER ALL = NOPASSWD: /usr/sbin/service ServiceName *

But that did not work, I am using Red hat 6,

User name is ahmed
Service name : nagios 
Fabby
  • 5,836
  • 2
  • 22
  • 38
John
  • 23
  • 3
  • Welcome to Unix & Linux. Sorry for the edited title but there are multiple ways of doing things and I'll be giving you one. Whichever is "the best" is opinion-based, which is off-topic on this site. – Fabby Sep 19 '18 at 16:20
  • In what way did it "not work"? – Jeff Schaller Sep 19 '18 at 16:28
  • Thanks Fabby, I am sorry if this is off topic, I am kinda new here so I was trying to get help from the Galaxy people. – John Sep 19 '18 at 16:29
  • and did you type in the literal line `USER ALL`..., or did you use `ahmed ALL`...? – Jeff Schaller Sep 19 '18 at 16:29
  • I never messed with visudo file, Thanks Jeff I was using USER ALL not Ahmed ALL @JeffSchaller – John Sep 19 '18 at 16:30

1 Answers1

1

According to the Nagios Documentation, Nagios is still init-based, so to allow any user to start and stop the Nagios service, we're going to:

  • create an operator Command alias
  • create an operator group
  • allow anyone in the operator group to start/stop the Nagios Service:
  • As an example, add the user "ahmed" to the operator group (as per your question)

first change the sudoers file:

sudo visudo

in the section # Cmnd alias specification add:

Cmnd_Alias      CMD_OPERATOR=/etc/rc.d/init.d/nagios

in the ### User privilege specification section ### add:

# Allow the group "operator" to use certain applications
%operator       ALL=CMD_OPERATOR

Now create the group operator:

sudo groupadd operator

and add ahmed to the operator group:

sudo usermod --append --groups operator ahmed

That's it! Now ahmed can perform all these commands:

sudo /etc/rc.d/init.d/nagios start
sudo /etc/rc.d/init.d/nagios reload
sudo /etc/rc.d/init.d/nagios stop

by providing his own password.

Why?

Well, now you have an operator group, you can:

  • easily add other programs these kind of users need to perform
  • easily revoke their operator rights if needed
Fabby
  • 5,836
  • 2
  • 22
  • 38