Ubuntu: Using Sudo to Grant User Privileges

If you have used your fresh Ubuntu install for longer than half an hour, chances are that you've discovered the sudo command already.

sudo allows certain users to execute a command under another user's privileges. Most commonly, using sudo implies running a command as a superuser, but the approach works equally well for allowing you to inherit a user ID (uid) and group ID (gid) of any user on the system.

To gain access, a password is asked, and by default it is your password, and not the password of a user you're trying to run a command as. This allows for the system' s administrator to effectively manage user privileges without having any user share their password.

sudo is based off the /etc/sudoers file, which should be edited by root employing the visudo command. WARNING: although /etc/sudoers file is a regular text which root can edit manually, ONLY visudo way of updating it is recommended, as this command, apart from editing capabilities, also does a syntax check of the changes before applying them to prevent user privilege related disasters.

If you want to grant superuser privileges to a particular user, the following line should be added to the /etc/sudoers file (just type visudo to invoke the editor):

greys ALL=(ALL) ALL

In this example, greys is the username.

Related books

If you want to learn more, here's a great book:


Ubuntu Kung Fu

  • Pingback: visudo tutorial | UNIX Tutorial: Learn UNIX()

  • ballack

    by mistake i disabled my user privileges, and now i'm not able to enable them again, so please kindly help me

  • Hi Maharaj, if you can't find anyone else with sufficient privileges for your system, you'll need to boot it into single user mode and edit /etc/sudoers from there.

    Read here for more details: https://help.ubuntu.com/community/RootSudo, and if you can't figure it out – please confirm the exact distro and version of your Linux OS

  • Colben

    I have added a user to the admin group but once I login with that user it does not list his directories as I go from dir's and it does not autocomplete comands when using tab key. Its on ubuntu server v10 please please please help!!!

  • Hi Colben,

    double-check which directory you log into once you provide password – just do pwd to confirm where in the filesystem you are.
    Are you saying you don't see any files or that you're getting a permission denied when doing ls?