Valid for VPS+, VPS, Cloud Servers, Dedicated Servers, and Bare Metal Servers.

By default, the root user is set up when Linux is installed. This user has full privileges to administer the operating system. Other users do not initially have administrator privileges. Authorized users can run programs with root privileges using the sudo command. This article explains how to create a sudo-enabled user.

Create a user

AlmaLinux 8/9/10 and Rocky Linux 8/9/10

  • Log in as the root user on the desired server.

  • To create a new user, enter the following command:

    [root@localhost ~]# adduser USERNAME

    Example:

    [root@localhost ~]# adduser user1

  • To set the new user’s password, enter the following command:

    [root@localhost ~]# passwd USERNAME

    Example:

    [root@localhost ~]# passwd user1

  • Enter the desired password and repeat it.
     

Debian 12/13 and Ubuntu 24.04/26.04

  • Log in as the root user on the desired server.

  • To create a new user, enter the following command:

    [root@localhost ~]# adduser USERNAME

    Example:

    [root@localhost ~]# adduser user1

  • Enter the desired password and confirm it.

Note

In Ubuntu 26.0, visual feedback (asterisks) is provided when setting a password.

  • Optional: Enter additional user information. To skip entering this information, press the Enter key.

    Changing the user information for user1
    Enter the new value, or press ENTER for the default
    Full Name [ ]:
    Room Number [ ]:
    Work Phone [ ]:
    Home Phone [ ]:
    Other [ ]:
    Is the information correct? [Y/n]

  • Type Y and press the Enter key.
     

SUSE Linux

  • Log in as the root user on the desired server.

  • To create a new user, enter the following command:

    localhost: ~ # useradd USERNAME

    Example:

    localhost: ~ # useradd user1

  • To set the new user’s password, enter the following command:

    localhost: ~ # passwd USERNAME

    Example:

    localhost: ~ # passwd user1

  • Enter the desired password and repeat it.

Test sudo and install it if necessary

  • Check whether sudo is installed. To do this, enter the following command:

    sudo ls -la /root

    If the message bash: sudo: command not found appears, sudo is not installed.
    If sudo is already installed, you can skip this step. To install sudo, enter the following command:

  • AlmaLinux 8/9/10 and Rocky Linux 8/9/10
  • dnf install sudo -y

  • Debian 12/13 and Ubuntu 24.04/26.04
  • apt install sudo

  • SUSE Linux
  • zypper in sudo

  •  

Install Vim

If the Vim editor is not installed, enter the following command(s) to install it:

AlmaLinux 8/9/10 and Rocky Linux 8/9/10

dnf install vim

Debian 12/13 and Ubuntu 24.04/26.04

apt install vim

SUSE Linux

zypper search vim
zypper install vim

Granting a user sudo privileges

AlmaLinux 8/9/10 and Rocky Linux 8/9/10

To grant a user sudo privileges in AlmaLinux and Rocky Linux, you must add them to the wheel group. To add the user to this group, enter the following command:

[root@localhost ~]# usermod -aG wheel USERNAME

Example:

[root@localhost ~]# usermod -aG wheel user1

To check whether the change was successful, enter the following command:

[root@localhost ~]# groups USERNAME

Example:

[root@localhost ~]# groups user1


Debian 12/13 and Ubuntu 24.04/26.04

To grant a user sudo privileges in Debian and Ubuntu, you must add them to the sudo group. To add the user to this group, enter the following command:

[root@localhost ~]# usermod -aG sudo USERNAME

Example

[root@localhost ~]# usermod -aG sudo user1

To check whether the change was successful, enter the following command:

[root@localhost ~]# groups USERNAME

Example:

[root@localhost ~]# groups user1

 

SUSE Linux

To grant a user sudo privileges in SUSE Linux, proceed as follows:

  • Search for the packages system-group-wheel and system-user-mail. To do this, enter the following command:

    [root@localhost ~]# zypper se wheel mail

  • To install the packages, enter the following commands:

    [root@localhost ~]# zypper install system-group-wheel
    [root@localhost ~]# zypper install system-user-mail

  • Open the file /etc/sudoers using the vim editor. To do this, enter the following command:

    [root@localhost ~]# visudo

  • Ensure that the following lines are no longer commented out. To do this, remove the # symbol at the start of the line if necessary:

    # Defaults targetpw   # ask for the password of the target user i.e. root

    and

    # ALL   ALL=(ALL) ALL   # WARNING! Only use this together with 'Defaults targetpw'!

Note

The vim editor has an insert mode and a command mode. You can enter insert mode by pressing the i key. In this mode, the characters you type are inserted into the text immediately. To enter command mode, press the ESC key afterwards. When you are in command mode, your keystrokes are interpreted as commands.

Please Note

If you only remove the comment from the line Defaults targetpw and leave the line ALL ALL=(ALL) ALL # WARNING! commented out, all users will have access to the root level of the utilities by entering their own password.

  • Look for the entry User privilege specification.

  • To grant all members of the wheel group the rights to execute all commands, you must remove the # at the start of the following line to uncomment it:

    # %wheel ALL=(ALL) ALL

  • To save the changes, press the Esc key and then enter the following command:

    :wq

  • To grant a user sudo privileges, you must add them to the ‘wheel’ group. To add the user to this group, enter the following command:

    [root@localhost ~]# usermod -a -G wheel USERNAME

    Example:

    [root@localhost ~]# usermod -a -G wheel user1

  • To check whether the change was successful, enter the following command:
     

    [root@localhost ~]# groups USERNAME

    Example:

    [root@localhost ~]# groups user1

  • Create the file /etc/sudoers.d/userpw using vi. To do this, enter the following command:

    [root@localhost ~]# vi /etc/sudoers.d/userpw

  • Add the following entry:

    Defaults !targetpw

  • To save the changes, press the Esc key and then enter the following command:

    :wq

Test a user with sudo privileges

To check whether the sudo permissions are working, complete the following:

  • To switch users, enter the following command:

    [root@localhost ~]# su - USERNAME

    Example:

    [root@localhost ~]# su - user1

  • List the contents of the /root directory. To do this, enter the following command:

    [user1@localhost root]$ sudo ls -la /root

  • If you are using sudo for the first time in a session, you will be prompted to enter the user’s password.

  • Enter the user’s password.