Recently, I wrote a script to automate the task of mounting the shared folders in Guest OS (Ubuntu 9.10) from Host OS (Windows 7), courtesy of VirtualBox. Now, I couldn’t run that script because I needed root privileges 😐 Although, I have installed the Guest OS, so I know the root password.
However, when VM boots, I am logging in with user account created while installing Guest OS. So, to run certain commands that need root privileges, I have to explicitly use sudo and then enter password, when prompted.
Now, surfing the web led me to a solution, i.e. edit /etc/sudoers file that contains list of privileges given to root and other users. So, to edit this sudoers list, one must run the following;
You’re prompted for password, enter it and then, you would see something like this;
# /etc/sudoers ## This file MUST be edited with the 'visudo' command as root. ## See the man page for details on how to write a sudoers file.# Defaults env_reset # Host alias specification # User alias specification # Cmnd alias specification # User privilege specification root ALL=(ALL) ALL # Uncomment to allow members of group sudo to not need a password # (Note that later entries override this, so you might need to move # it further down) # %sudo ALL=NOPASSWD: ALL # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL
As you can see, the last statement implies that if any user account belongs to admin group, then that user account will have privileges of a super user. So, if I run the following command again, for instance;
I won’t get any prompt for password and /etc/sudoers without delay.
Trick 2 Gain Root Privileges..
So, go to “System > Administration > Users and Groups” and click on the account properties you want to assign root privileges. Then, switch to “Advanced Tab“, change the “Main Group” to admin. Now, if you have followed till here, it’s time to make following changes to /etc/sudoers file;
# Members of the admin group may gain root privileges %admin ALL=(ALL)NOPASSWD: ALL
Now, you have root privileges, you may now run the commands that need root permissions without getting prompt for password. Try doing the same for the script I mentioned in the beginning.