Adding a user to the sudoers list in Ubuntu
Stop using root for administrative tasks. Here is how to add a new user to the sudoers list in Ubuntu.
When adding a new user on a Linux system, it's not automatically added to the list of sudoers, which is what's required for the user to have root privileges.
If you need to add a new user with root privileges, then do the following.
Add a new user by running the adduser
command followed by the username.
# adduser rasmus
Adding user `rasmus' ...
Adding new group `rasmus' (1000) ...
Adding new user `rasmus' (1000) with group `rasmus' ...
Creating home directory `/home/rasmus' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for rasmus
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
Now add the newly added user to the group sudo
.
# usermod -aG sudo rasmus
That's it. This works on Ubuntu because the group sudo is listed in the sudoers file.
%sudo ALL=(ALL) ALL
If you log on as the newly created user, you can try to run something like the following in order to test that it works.
$ sudo apt-get update