sudoare the preferred way to handle elevated permissions. In the supported version of Ubuntu, using the sudo command will give high permission for 15 minutes.
Standard user accounts are prohibited from performing sensitive tasks, such as viewing directory/root content. This prevents accidental user commands with big consequences. This also makes it more difficult for intruders to compromise with a system. But sometimes, you need to run administrative commands. Sudo – or Super User Do – gives you privileges to run sensitive tasks.
This simple tutorial will show you how to create and add new users on Ubuntu and give sudo access.
Important: By having this sudo user account, you will often use users with sudo privileges to install various packages which I will explain in the following tutorials, all of which are required to use permissions as sudo users.
- Systems running supported Ubuntu versions
- Access to the root user account or another account with sudo rights
- Access to terminal window/command line (
What is Sudo?
Sudo is a program for a computer operating system similar to Unix that allows users to run other users’ security rights programs, by default they are “superusers”. Its origin stands for “superuser do” because sudo in earlier versions was designed to run programs only as superuser.
However, later versions added support for running commands not only as a superuser but also as another (restricted) user, so they were also generally developed as “substitute user do”. Although the latter case reflects current functionalities more accurately, sudo is still often called “superuser do” because it is often used for administrative tasks.
Steps for Creating and Adding Sudo Users on Ubuntu
Step 1: Create a new user
1. Enter the system with the root user or an account with sudo rights.
2. Open a terminal window and add a new user with the command:
$ adduser newuser
The adduser command creates a new user, creates a group and the home directory for that user.
You might get an error message that you have insufficient privileges. (This usually only happens for non-root users.) Please type the following command and enter:
$ sudo adduser newuser
3. You can replace the new user with the user name you want. The system will add a new user; then asks you to enter your password. Enter a great secure password, then retype to confirm.
4. The system will ask you to enter additional information about the user. This includes names, telephone numbers, etc. – this field is optional, and you can skip it by pressing Enter.
Step 2: Add users to the sudo group
Most Linux systems, including Ubuntu, have a user group for sudo users. To give new users higher rights, add them to the sudo group.
At the terminal, enter the command:
$ usermod –aG sudo newuser
Replace the new user with the user name you entered in Step 1.
Once again, if you get an error, run the command with sudo as follows:
$ sudo usermod –aG newuser
The – aG option tells the system to add users to the specified group. (Option – a is only used with G. )
Step 3: Verify user Belongs to the sudo group
Enter the following command to view the groups that belong to the user:
$ groups newuser
The system will respond by registering the user name and all groups it has, for example: newuser: newuser sudo
Step 4: Verify sudo Access
Change user by entering:
$ su – newuser
Change the new user to the user name you entered in Step 1. Enter your password when prompted. You can run the command as usual, just by typing it.
As an example:
$ ls /home
However, some orders or locations require higher rights. If you try to list the contents of the directory /root , you will get an access error denied:
Commands can be executed by:
sudo ls /root
The system will ask for your password. Use the same password as the one you set in Step 1. Now you will see the contents of the / root directory.
Now you know how to add and create users with sudo rights on Ubuntu. Before sudo, users will enter their system with full permission for the whole system. This is risky because users can be exploited by tricking them into entering malicious commands. This vulnerability was resolved by limiting account privileges. However, administrators still have to log out of their accounts and log into the admin account to do routine tasks.
The sudo command on Ubuntu creates a user account that protects the balance from the possibility of dangerous or accidental damage while allowing users who have privileges to carry out administrative tasks.