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.
Applies to: Linux OpenSSH Blue Arctic VPS Hosting and Virtual Dedicated Servers (VDS); Ubuntu, Debian and AlmaLinux
On this page
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
sudoand a space in front of each command below.
Step 1: Check which Linux you have
- Run
cat /etc/os-release. This only shows information about your system. - Look at the
NAMEandID_LIKElines. 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
- Run
useradd -m alex. This creates the user;-malso creates a home folder. It prints nothing when it works. - Run
passwd alexand type a strong password twice. Nothing appears on screen while you type. - Run
usermod --append -G wheel alex. This adds alex to thewheelgroup, which may use sudo, and keeps alex’s other groups. It prints nothing when it works. - Run
grep '^%wheel' /etc/sudoers. This only reads the file. You should see a line starting%wheeland endingALL(the spacing may differ). If nothing is printed, don’t edit the file: open a support ticket.
Step 2b: Ubuntu or Debian
- Run
adduser alex. Type a strong password twice; nothing appears while you type. Press Enter to skip the name and phone questions, then typeYand press Enter when asked if the information is correct. - Run
adduser alex sudo. This adds alex to thesudogroup, which may use sudo.
Step 3: Test in a second window
- Leave the root session open.
- 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 PORTif your port is 22). - Run
sudo whoami. The first time, you may see a short message about using sudo carefully; that’s normal. - 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) ordeluser 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) ordeluser 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 alexand check thatwheelorsudois listed. Then log out as alex and log in again. sudo: command not found(Debian): sudo isn’t installed. In your root session, runapt install sudoto 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.