Tuesday, April 1, 2014

Quick & Dirty Add User to SUDOERs (*nix)

While there is near endless and very powerful ways to configure user permissions, you've just spun up a virtual machine using VMWare or Virtual Box and you want God permissions for your user so you're not always becoming root (and then forgetting that you're root). The following example is from CentOS 6.5. Since you can destroy a system if you muck up the sudoers file just using any old text editor is not recommended. Hence, we shall use visudo.

[myuser@machine ~]$ su -
Password:
[root@machine ~]# visudo

This will open your sudoers file for editing. visudo will protect you from some, but not nearly all mistakes. So, for this quick dirty example search for the following section:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
Then, add the following directly below it:
myuser ALL=(ALL) ALL
The end result should look like:
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
myuser ALL=(ALL) ALL
NOTE: The above is separated by TABS so you would type it as follows:
myuser[TAB]ALL=(ALL)[TAB]ALL

Save & close (:wq) 

[root@machine ~]# exit
[myuser@machine ~]$ sudo someCommand

FIN