How to Create a New Sudo User in Linux

If you’re a Linux user, you’re likely familiar with the power and flexibility it offers. One essential aspect of administering a Linux system is user management, which includes creating new users, assigning administrative privileges, and switching between user accounts. In this tutorial, we’ll walk you through the process of creating a new user account with sudo (admin) privileges, switching to that account, and confirming it’s access.

Prerequisites

  1. Linux Operating System: Make sure you are using a linux based operating system. While the steps provided here likely will work across various distributions, we are using Ubuntu Server 22.04.
  2. Root Access: Access to the root account is crucial for performing administrative tasks. Before proceeding with this tutorial, ensure you have the root account credentials to log in and make system-wide changes.
  3. Basic Terminal Knowledge: Familiarity with the Linux terminal is essential. You should be comfortable navigating the command line, entering commands, and interpreting their output.

Step 1: Logging in with the Root Account

To start make sure you are logged in with the root account. The root account has unrestricted to system resources making it the “root” of all administrative tasks on the computer or server.

Step 2: Creating a New User Account

To create the new user account we’ll use the adduser command. This command accepts an argument as the new username desired for the new account.

adduser [username]

Replace [username] with the desired account name for the new user. It will prompt you to enter then confirm a new password, as well as fill out some basic information about the user, such as a full name and other information.

Step 3: Assigning Sudo Privileges

Sudo privileges grant a user administrative rights without requiring them to log in as the root user. To assign sudo privileges to the new user, we’ll use the usermod command.

usermod -aG sudo [username]

This command adds the user to the ‘sudo’ group, allowing them to execute commands with elevated privileges.

Step 4: Switch to the New User Account

To switch to the newly created user account, use the su (substitute user) command followed by the username.

su [username]

Replace [username] with the name of the newly created user. You will be prompted to enter the user’s password. Once entered correctly, you will be logged into the new user account.

Step 5: Confirm Sudo Privileges

To verify that the user has been granted sudo privileges, we can check their current privileges by running a sudo command. For example, we can use the following command to check the current user’s identity:

sudo whoami

If the user has been properly added to the ‘sudo’ group, this command will return root, indicating that the user has sudo privileges.

Congratulations! You have successfully created a new user account, assigned it sudo privileges, switched to that account and confirmed its privileges. Linux’s user management capabilities provide a robust foundation for a secure and efficient computing environment. By following these steps, you’re well on your way to effectively managing user accounts, permissions, and switching between accounts on your Linux system.