Adding a non root user to the sudoers list
by Ritesh
Posted on September 18, 2017 at 7:30 PM
sudo command allows a normal user to run root user commands. It is a must in Linux distributions such as Ubuntu that blocks root login.
My favorite is "sudo-s" which is particularly helpful during long installations and I dont have to type sudo before every command.Unless your user is in the sudoers list, you should encounter an error as shown below:
Now how to fix this
Method 1 : usermod
sudo usermod -a -G sudo <username>

This method did not work for me in Centos because there is no sudo group by default.
Method 2 : visudo file edit. It opens the sudoers file (usually located at /etc/sudoers )
sudo visudoAfter the file opens press i to insert the following after root ALL=(ALL) ALL
<username> ALL=(ALL) ALL
Now press Ctrl+X and press Y to save. You can also use vi command :wq

Method 3 (Shortcut for Method 2): echo ‘ username ALL=(ALL) ALL’ >> /etc/sudoers .
Thats it !