Sudo Command – Control User To Run Commands with Root Privileges

Sudo Command – Control User To Run Commands with Root Privileges

Sudo is a program in unix like operating systems which allow the users to run the program which require the super user or root user permissions. SUDO stands for the “superuser do”. It prompts you for your personal password and confirm your request by checking a file called sudoers.Sudoers file contains the rule that user must follow when using sudo command. This file is configure by the root/super user to allow specific users to run privileged commands. It also maintains the logs and records of the what command run and who run the command at what time. Below is the syntax of sudo commands:

sudo command

The two best advantages about using sudo command are:

  • Restricted privileges
  • Logs of the actions taken by users

You can provide the sudo permissions to users and groups by configuring sudoers file. The location of sudoers file is /etc/sudoers. To edit this file open this in your favorite text editor or you can directly open this file by running the following command on terminal as a root user.

~]# visudo

This will open the sudoers file in the vi editor. By defaults all the lines are commented in this file. In order to provide sudo permissions to a specific user add the following line to the file:

username ALL=(ALL) ALL

This will provide the all root permissions to a specific user. If you want allow a user(s) to run some commands as root, this can be achieved by creating command alias in your sudoers file:

User_Alias ADMINS = user, user1, user2
Cmnd_Alias HTTPD = /etc/init.d/httpd
ADMINS ALL = HTTPD

User_Alias creates groups of users to whom you can assign command alias. Cmnd_Alias list the various command which User_Alias can run. The user alias then assign the command alias.

This is simple way of assigning sudo permissions to users and groups. Sudo permissions is also used by the most of the admins for the security reasons while working on the systems/server, as it prompt for the password to confirm the request. If you dont want user to enter password each time when they run a sudo command, just replace the above with the following:

ADMINS ALL = NOPASSWD: HTTPD

You can now allow the different users to run various commands using the sudo command. If you need more details you can read the man page for sudo command by hitting “man sudo” in your terminal.