How to Create a Non-Root Sudo User on Ubuntu 24.04

  • Francis Ndungu

Introduction

A non-root sudo user is a regular user account with administrative privileges. You can use it to perform system administration tasks without using the root account. This practice enhances security by limiting the use of the root account, reducing the risk of accidental or malicious system changes. Non-root sudo users also allow you to delegate specific administrative tasks to other users while maintaining control over the system.

This article shows you how to create a non-root sudo user on Ubuntu 24.04.

Prerequisites

Before you begin, ensure you've:

Create a Non-Root Sudo User

In this section, you will create a new user named smith and grant the user sudo privileges.

  1. Create a new user. The adduser command prompts you to enter and confirm the new user's password and provide additional information such as full name and contact details.

    CONSOLE
    $ sudo adduser smith
    
  2. Add the new user to the sudo group. This command grants the new user sudo privileges by adding them to the sudo group.

    CONSOLE
    $ sudo adduser smith sudo
    

Verify the New Sudo User

In this section, you will verify that the new user has sudo privileges.

  1. Switch to the new user account.

    CONSOLE
    $ su - smith
    
  2. Run the following command with sudo privileges. You will be prompted to enter the password for the new user.

    CONSOLE
    $ sudo whoami
    

    If the new user has sudo privileges, the command will return root.

    Output:

    root
    

Conclusion

You have created a non-root sudo user on your Ubuntu 24.04 server. This guide covered creating a new user, setting a password, and granting sudo privileges. You also verified that the new user has sudo privileges. Using non-root sudo users enhances security and allows you to delegate administrative tasks without compromising the root account. You can now use the new user account to perform system administration tasks securely.

  • Databases
  • Webservers
  • PHP
  • API
  • Python
  • VPS Guides
  • Network
  • AI
  • Node.js