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!!

Shahrukh Khan
  • 201
  • 2
  • 5
  • 10

2 Answers2

1

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.
Suyash Jain
  • 241
  • 2
  • 9
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
Eric
  • 554
  • 1
  • 5
  • 15