How to Create Sudo Users and Sudo Group on Ubuntu – Orders
sudo is the preferred way of handling elevated clearance. In supported versions of Ubuntu, using the sudo command will grant high permissions for 15 minutes.
Standard user accounts are prohibited from performing sensitive tasks, such as viewing the contents of the / root directory. This prevents accidental use of commands with huge consequences. It also makes it harder for intruders to compromise a system. But sometimes, you need to run administrative commands. Sudo – or Super User Do – gives you the privilege to perform sensitive tasks.
This simple tutorial will show you how to create and add a new user in Ubuntu and grant sudo access.
Urgent : By having this sudo user account, you will often use a user with sudo privileges to install various packages which I will describe in subsequent tutorials, all of which are required to use the privileges of the sudo user.
- A system running a supported version of Ubuntu
- Access to the root user account or any other account with sudo privileges
- Access to a terminal window / command line (
What is Sudo?
Sudo is a program for Unix-like computer operating systems that allows users to run other users’ security rights programs, by default being the “superuser”. It originally stood for “superuser do” because sudo in earlier versions was designed to run programs only as a superuser.
However, later versions add support for running commands not only as a superuser but also as another restricted user, so it is generally developed as a “substitute user do”. Although the latter case more accurately reflects current functionality, sudo is still often called “superuser do” because it is often used for administrative tasks.
Steps to Create and Add a Sudo User in Ubuntu
Step 1: Create a New User
1. Log on to the system with the root user or an account with sudo privileges.
2. Open a terminal window and add a new user with the command:
$ adduser newuser
Command adduser create a new user, create a group and a 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 any user name you want. The system will add a new user; then asks you to enter a password. Enter a strong secure password, then retype it to confirm.
4. The system will ask you to enter additional information about the user. This includes your name, phone number, etc. – this field is optional, and you can skip by pressing Enter.
Step 2: Add the user to the sudo group
Most Linux systems, including Ubuntu, have a user group for the sudo user. To give new users higher privileges, add them to the sudo group.
At the terminal, enter the command:
$ usermod –aG sudo newuser
Replace the new user with the username you entered in Step 1.
Again, if you get an error, run the command with sudo as follows:
$ sudo usermod –aG newuser
Option –aG tells the system to add the user to the specified group. (Option –a only used with G..)
Step 3: Verify the user belongs to the sudo group
Enter the following command to see which groups the user belongs to:
$ groups newuser
The system will respond by registering the username and all the groups it belongs to, for example: newuser: newuser sudo
Step 4: Verify sudo access
Change user by entering:
$ su – newuser
Replace new user with the username you entered in Step 1. Enter your password when prompted. You can run commands as usual, just by typing them.
As an example:
$ ls /home
However, some commands or locations require higher privileges. If you try to list the contents of a directory / root, You will get an access denied error:
Commands can be executed by:
sudo ls /root
The system will ask for your password. Use the same password that you set in Step 1. You will now see the contents of the directory / root.
Now you know how to add and create a user with sudo privileges in Ubuntu.
Prior to sudo, the user would log on to their system with full system-wide permissions. This is risky because users can be exploited by tricking them into entering malicious commands. This vulnerability is resolved by limiting the account privileges. However, administrators still need to log out of their account and into an admin account to perform routine tasks.
The sudo command in Ubuntu creates a user account that protects the balance from possible malicious or accidental damage while allowing privileged users to perform administrative tasks.