On the Linux command prompt

# visudo
Allow a local user to run root commands

– Take for example the /sbin/shutdown command: by default, you won’t be able to execute it unless you have root privileges. In order to allow a local user (I’ll use softpedia as the example user) to shut down the computer, you’ll have to define the alias which represents the shutdown command by adding this line in the Cmnd aliassection:

CODE
# Cmnd alias specification
Cmnd_Alias SHUTDOWN = /sbin/shutdown

– Then, in the User privilege section, you’ll have to add the line:
CODE
# User privilege specification
softpedia ALL = SHUTDOWN

– Now, the user softpedia will be able to shutdown the computer by using the command:
# sudo shutdown -h now

– The sudo program will prompt users for their own password (not the root’s) before executing the command. If you wish to setup sudo for not prompting users for any password, edit the line in the User privilege section to look like this:

CODE
softpedia ALL = NOPASSWD: SHUTDOWN

Allow a local user to run root commands without sudo or su

NOTE: This will allow the specified user to run any command as root, without having to use su, sudo or constantly type in his or the root password.

– First, add the OWNER alias by adding the following lines in the User alias andUser privilege sections of /etc/sudoers file:

CODE
# User alias specification
User_Alias OWNER = softpedia

# User privilege specification
OWNER ALL = NOPASSWD: ALL

Allow users that are part of certain groups to run root commands

– You can define a group of people who are allowed to perform certain administration commands which require root privileges. This can be achieved by adding the following lines in the User alias, Cmnd alias and User privilegesections:

CODE
# User alias specification
User_Alias ADMINS = softpedia,john,david

# Cmnd alias specification
Cmnd_Alias UPDATE = /usr/bin/yum
Cmnd_Alias REBOOT = /usr/bin/reboot

# User privilege specification
ADMINS ALL = UPDATE, REBOOT

then login with simple user and run command
#sudo /sbin/fdisk -l    #if apply sudo on fdisk command

 

Leave a Reply