taT4Nix | Using visudo To Run Commands With Root Privileges

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.

Using visudo

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;

sudo visudo

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)

# 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;

sudo visudo

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

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.


One thought on “taT4Nix | Using visudo To Run Commands With Root Privileges

  1. Pingback: taT4Nix | Mount Shared Folders from Host OS in Guest OS « PrayogShala

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s