Allow normal user to run some commands as root – Linux

To allow user to run some commands which need root/sudo permission we need to add them in /etc/sudoers file.

I will show an example to give permission to start/stop/restart httpd (Apache web-server).

Open /etc/sudoers file with sudo/root permission using any text editor (Eg: vim) and following line at end of the file:

userabc ALL=/etc/init.d/httpd restart,/etc/init.d/httpd start,/etc/init.d/httpd stop

In above line userabc is the user name for which we are giving permission tor start/stop/restart httpd (Apache web-server).

Now save and exit from /etc/sudoers file.

To test above command login into userabc, and run any of the following command, it will ask for sudo password. We need to enter userabc password for as sudo password that will run the command.

$ sudo /etc/init.d/httpd restart

$ sudo /etc/init.d/httpd start

$ sudo /etc/init.d/httpd stop

Similarly you can add other command as per your requirement.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s