Here we can see how to add the sudo in Centos, In Ubuntu by Default sudo will be enabled, But in Centos and RHEL there is not sudo enabled by deafult, we can see here how to access the root privilage from other user by adding the user to Sudo Group.
Switch to Root user using su
Edit the Sudoer’s file using vim
# vim /etc/sudoers
Go to Line 98, Look for Below command
## Allow root to run any commands anywhere root ALL=(ALL) ALL
add this line, replacing [USERNAME] with your Respective username)
[USERNAME] ALL=(ALL) ALL
Here i have added a user named linuxmental to sudoer below
## Allow root to run any commands anywhere root ALL=(ALL) ALL linuxmental ALL=(ALL) ALL
Save the file and Exit using wq!
Then switch to normal user linuxmental and execute some commands with sudoers privilage.
[linuxmental@centos ~]$ sudo /etc/init.d/network restart Shutting down interface eth0:[ OK ]Shutting down loopback interface:[ OK ]Bringing up loopback interface:[ OK ]Bringing up interface eth0:[ OK ]
That’s it …