Allow a user to run specific sudo command only

06. March 2015 SysAdmin 0

Issue

  • I need to give permission to my develper to specific sudo command only.
  • I need to give permission to restart apache httpd service.

Versions

  • Any Linux Flavour. CentOS, RHEL, Ubuntu , SuSE etc

Solution

  • run visudo to get the sudo access editor.
  • add the below line to the file and save and exit

mydeveloper ALL=(ALL) NOPASSWD: /etc/init.d/httpd *

  • Now the devloper can run the below command to stop, start, restart httpd services `sudo /etc/init.d/httpd start sudo /etc/init.d/httpd stop sudo /etc/init.d/httpd restart`

Note

If you want to give the same access to a group of people,

  • Add those to a group.

gpasswd -a dev1 mydevelopergroup
gpasswd -a dev2 mydevelopergroup 
gpasswd -a dev3 mydevelopergroup 

  • Add the the below line to visudo

%mydevelopergroup ALL=(ALL) NOPASSWD: /etc/init.d/httpd *

Like / share / + / Tweat if found helpfull 🙂


Leave a Reply

Your email address will not be published.