• November 10, 2025

How to Create a Sudo User on a Linux Server

How to Create a Sudo User on a Linux Server

Learn how to create and configure a sudo user on Ubuntu, Debian, CentOS, AlmaLinux, Rocky Linux, and FreeBSD systems securely.

Creating a sudo user improves security by allowing you to perform administrative tasks without logging in as the root user. It helps reduce the risk of accidental system wide changes and improves auditing capabilities. By assigning sudo privileges to specific users, you can also achieve finer grained permission management and control who can perform administrative operations.

This article explains how to create a sudo user on multiple distributions, including Ubuntu, Debian, and FreeBSD.

Prerequisites

Before you begin, you need to:

  • Have access to a Linux server as a root or non-root user with sudo privileges.
Create a Sudo user on Ubuntu, Debian

Follow the steps below to create a new user and give them sudo privileges.

  1. Create a new user. Replace john with your desired username.
    console
    $ sudo adduser john

    When prompted, enter a password for the user and other additional information such as full name or phone number.

  2. Add the new user to the sudo group to grant sudo privileges.
    console
    $ sudo usermod -aG sudo john
  3. Switch to the newly created user account.
    console
    $ sudo su - john
  4. Run a sudo command to confirm that the user has sudo privileges.
    console
    $ sudo whoami

    When prompted, enter the user’s password. If the command returns root, it confirms that the user can execute commands with sudo privileges. For advanced configurations, such as managing password prompts or restricting specific commands, refer to this article.

Create a Sudo user on AlmaLinux, Rocky Linux, or CentOS.

Follow the steps below to create a new user and assign sudo privileges on AlmaLinux, Rocky Linux, or CentOS.

  1. Create a new user. Replace john with your preferred username.
    console
    $ sudo adduser john
  2. Set a password for the new user.
    console
    $ sudo passwd john

    When prompted, enter and confirm a secure password.

  3. Add the user to the wheel group to grant sudo privileges.
    console
    $ sudo usermod -aG wheel john
  4. Confirm that the wheel group is configured to allow sudo access.

    Open the sudoers file with visudo:

    console
    $ sudo visudo

    Ensure the following line is uncommented:

    ini
    %wheel ALL=(ALL:ALL) ALL

    This allows all users in the wheel group to run commands with sudo.

  5. Switch to the new user account.
    console
    $ sudo su - john
  6. Run a sudo command to test privileges.
    console
    $ sudo whoami

    Enter the user’s password when prompted. If the output is root, the user has successfully been granted sudo privileges.

Create a Sudo user on FreeBSD

Follow the steps below to create a new user and assign sudo privileges on a FreeBSD system.

  1. Install the sudo package.
    console
    # pkg update && pkg install sudo
  2. View the installed version of sudo.
    console
    # sudo -V
  3. Create a new user account.
    console
    # adduser

    When prompted, enter the username and other details such as UIDshell and password.

  4. Add the newly created user to the wheel group.
    console
    # pw usermod john -G wheel
  5. Open the sudoers file using visudo.
    console
    # visudo

    Make sure the following line is uncommented to allow users of the wheel group to use sudo.

    ini
    %wheel ALL=(ALL:ALL) ALL
  6. Switch to the new user account.
    console
    # su - john
  7. Run a sudo command to verify access.
    console
    $ sudo whoami

    When prompted, enter the user’s password. If the output is root, the user has sudo privileges.

Conclusion

In this article, you learned how to create a sudo user in Debian-based and FreeBSD systems. You created a new user, assigned the appropriate group membership (sudo or wheel), and verified administrative access using sudo. These steps improved system security by limiting direct root usage and enabled controlled, auditable administrative privileges across different operating systems.

Leave a Reply

Your email address will not be published. Required fields are marked *