Add User to Sudoers in Ubuntu Distribution

Before adding a user to the list of Sudoers, we would discuss a bit about sudo command and its significance. Sudo command is mainly used to instruct the Ubuntu/Linux to run a specific command with super user privileges. As a result, you could tweak anything in your Ubuntu/Linux distribution. Furthermore, if you are not careful while running commands as super user then, you may cause irreversible damage to your operating system.

A word of caution – you must use sudo command only when you know what you are doing to your operating system. Apart from that, if you wish to run any command/task with super user privileges then add prefix sudo to it. For Instance –

sudo nano /etc/hosts

Next, it will ask for users’ password. After providing the password you can edit the hosts file. If you are unable to get super user access even after providing your password. Then, you may have to ask system administrator to either provide you super user access or ask the system admin to do it for you. To provide you the super user access, the system admin will add you to sudoers list. We will discuss it next:

Add user to Sudoers

STEP – I: Login to your system with root access. Or, try one which has super user access.

STEP – II: Add a user, say username, with the help of useradd command.

sudo useradd username

STEP – III: Set password for the new user – username, through passwd command.

sudo passwd username

Next, we will log in with our newly created user – username. Then, type sudo whoami and enter password. It will return that we are not present in sudoers file.


check whoami


STEP – IV: Edit /etc/sudoers/ file with the help of a text editor. We have used nano, you can choose any text editor like gedit, mousepad, leafpad, vi, vim etc.

sudo nano /etc/sudoers

sudoers file


If you see a group sudo in the sudoers file, all you have to do is add your user to this group. However, if the group is not present in your sudoers file then make an entry similar to one shown above.

STEP – V: Add user to the group sudo.

sudo usermod -aG sudo username

STEP – VI: To verify, if we have successfully completed all the steps:

su username
sudo whoami


Once we type groups, it will return with our group as mentioned in Step – IV. Then, with whoami command it would recognize us as root.

Thus, we have successfully added user to the sudoers file.