1

I have a Non Root User abc and want to give the user sudo rights only to restart, start or stop - mysqld service. i.e sudo service mysqld restart. How can I do it so?

I would like to do the same to usergroup too!!

0

2 Answers 2

2

You need to add the following lines in /etc/sudoers

dba01 ALL=/sbin/service mysqld start
dba01 ALL=/sbin/service mysqld stop
dba01 ALL=/sbin/service mysqld restart

this config will allow dba01 user to execute all three commands.

Now here is the output

[dba01@APP01 root]$ sudo /sbin/service mysqld restart
[sudo] password for dba01:
Shutting down mysqld:                                        [  OK  ]
Starting mysqld:                                             [  OK  ]

If you try to run any other service

[dba01@APP01 root]$ sudo /sbin/service ip6tables restart
Sorry, user dba01 is not allowed to execute '/sbin/service ip6tables restart' as root on APP01.
4
  • You don't need all three lines; allowing /sbin/service mysqld will grant permission to run it with any arguments.
    – Jenny D
    Oct 15, 2015 at 10:57
  • no , I tested it , it does not work without full command Oct 15, 2015 at 11:04
  • could you please tell my the same for user groups too....i have updated my question Oct 15, 2015 at 13:39
  • use %groupName rather dba01 Oct 20, 2015 at 8:12
0

granting permissions to allow the group to run sudo service, would give them permission to restart any service. I would simply grant them access to the init script.

You can do this by adding the following line to the sudoers file

%groupName ALL=(ALL) NOPASSWD: /etc/init.d/mysql

Then the group members should be able to run

sudo /etc/init.d/mysql restart
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql restart
3
  • please explain in detail step by step Oct 15, 2015 at 14:28
  • i used sudo visudo to go to sudoers file....then i added a line User_Alias GROUPONE = abc1,abc2,abc3,... Oct 15, 2015 at 14:32
  • After that i added this line %GROUPONE ALL=(ALL) NOPASSWD: /etc/init.d/mysql Oct 15, 2015 at 14:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .