Browse help topics

Security

How to Create a Linux User With sudo Access

As root, create the user (adduser on Ubuntu and Debian, useradd and passwd on AlmaLinux) and add it to the sudo or wheel group. Test it in a second SSH window with sudo whoami before you close your root session.

  • Updated
  • Last reviewed
  • Intermediate
  • About 10 minutes

Applies to: Linux OpenSSH Blue Arctic VPS Hosting and Virtual Dedicated Servers (VDS); Ubuntu, Debian and AlmaLinux

On this page
  1. Before you start
  2. Step 1: Check which Linux you have
  3. Step 2a: CloudLinux, AlmaLinux and other Red Hat family systems
  4. Step 2b: Ubuntu or Debian
  5. Step 3: Test in a second window
  6. How to tell it worked
  7. How to undo it
  8. Troubleshooting
  9. Still need help?

Working as root (the main administrator account, which can change anything) all the time is risky: one mistyped command can damage the whole server. A separate user with sudo rights works normally and runs an administrator command only when you put sudo in front of it.

Before you start

  • This creates a user for managing the server itself. To add a website or hosting account on a server with cPanel/WHM or Plesk, use the control panel instead.
  • Warning: keep your current root session open until the new user works. Don’t edit /etc/sudoers (sudo’s settings file) yourself; a mistake there can stop sudo working.
  • Every VPS and VDS plan comes with Core Managed: we look after the server underneath your applications, such as OS security patches, Imunify360 and the control panel. Inside the server, root is yours. Before you change SSH settings, such as which users may log in, open a support ticket.
  • If you’re logged in as a user with sudo rather than root, put sudo and a space in front of each command below.

Step 1: Check which Linux you have

  1. Run cat /etc/os-release. This only shows information about your system.
  2. Look at the NAME and ID_LIKE lines. If they mention rhel, centos or fedora (for example CloudLinux, AlmaLinux or Rocky Linux), use Step 2a. If they mention ubuntu or debian, use Step 2b. If you see something else, open a support ticket before you continue.

The examples use the username alex. Choose your own: start with a lowercase letter, then use lowercase letters or numbers, with no spaces.

Step 2a: CloudLinux, AlmaLinux and other Red Hat family systems

  1. Run useradd -m alex. This creates the user; -m also creates a home folder. It prints nothing when it works.
  2. Run passwd alex and type a strong password twice. Nothing appears on screen while you type.
  3. Run usermod --append -G wheel alex. This adds alex to the wheel group, which may use sudo, and keeps alex’s other groups. It prints nothing when it works.
  4. Run grep '^%wheel' /etc/sudoers. This only reads the file. You should see a line starting %wheel and ending ALL (the spacing may differ). If nothing is printed, don’t edit the file: open a support ticket.

Step 2b: Ubuntu or Debian

  1. Run adduser alex. Type a strong password twice; nothing appears while you type. Press Enter to skip the name and phone questions, then type Y and press Enter when asked if the information is correct.
  2. Run adduser alex sudo. This adds alex to the sudo group, which may use sudo.

Step 3: Test in a second window

  1. Leave the root session open.
  2. In a new PowerShell or Terminal window, connect as the new user, for example ssh -p PORT alex@203.0.113.10 (leave out -p PORT if your port is 22).
  3. Run sudo whoami. The first time, you may see a short message about using sudo carefully; that’s normal.
  4. When you see [sudo] password for alex:, type alex’s password (not root’s) and press Enter.

How to tell it worked

sudo whoami prints root. You can now do everyday work as this user and use sudo for administrator commands.

Tip

Give the new user an SSH key too; see how to set up SSH key authentication.

How to undo it

  • Remove sudo rights only: gpasswd -d alex wheel (Red Hat family) or deluser alex sudo (Ubuntu, Debian).
  • Remove the user: first log out of every session where you’re logged in as alex. Then run userdel alex (Red Hat family) or deluser alex (Ubuntu, Debian). The home folder and its files stay on the server.
  • Never remove the only user you can log in with.

Troubleshooting

  • “alex is not in the sudoers file”: the group step didn’t take effect. In the root session, run groups alex and check that wheel or sudo is listed. Then log out as alex and log in again.
  • sudo: command not found (Debian): sudo isn’t installed. In your root session, run apt install sudo to install it, then test again.
  • The new user can’t log in over SSH: check the password. Some servers accept only SSH keys, or allow only certain users to log in. Don’t change that yourself: open a support ticket.

Still need help?

Open a support ticket from the Client Portal at my.bluearctic.com. Our support page explains how the 24/7 helpdesk works. Include your VPS IP address, the Linux name from /etc/os-release, the commands you ran and the exact error text. Never include a password or a private key.

Was this article helpful?

Report outdated instructions or suggest an improvement
Type of report

Please do not include passwords or personal information.

Still need help?

Our support team can look into your account and walk you through it.