How to Create a Linux User With sudo Access
As root on CloudLinux or another Red Hat family system, create the user with useradd and passwd, then add it to the wheel group, which may use sudo. If your server runs Ubuntu or Debian instead, use adduser and the sudo group. Test it with sudo whoami before you close your root session.
Applies to: Linux OpenSSH Blue Arctic VPS Hosting and Virtual Dedicated Servers (VDS); CloudLinux and other Red Hat family systems
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. Not sure whether the work is covered by your plan? Open the ticket and we’ll tell you.
- 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
IDandID_LIKElines (some systems, such as Debian, have noID_LIKEline). If they mention cloudlinux, rhel, centos, fedora, almalinux or rocky, 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 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. A line startingBAD PASSWORDmeans the password is too weak: press Ctrl+C and run the command again with a stronger one. - Run
usermod --append -G wheel alex. This adds alex to thewheelgroup, which may use sudo, and keeps alex’s other groups. - 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: If your server runs Ubuntu or Debian instead
- 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 before you close the root session
- In your open session, run
su - alex(if you aren’t root,sudo su - alex). This switches you to alex; the prompt now showsalex. - 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. It should printroot. - Type
exitand press Enter to go back to your own session. Leave it open. - Now test the login. 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). If it fails, see Troubleshooting.
How to tell it worked
sudo whoami prints root, and alex can log in from a second window. 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). - Warning: Never remove the only user you can log in with. Use one of the next two commands, not both: the second deletes everything in
/home/alexfor good. - Remove the user and keep the home folder: log out of every session where you’re logged in as alex, then run
userdel alex(Red Hat family) ordeluser alex(Ubuntu, Debian)./home/alexstays on the server, with any SSH keys in it. A user created later with the same name can get that folder and those keys. - Remove the user and the home folder together: log out as alex, then run
userdel -r alexinstead.
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: sudo isn’t installed. In your root session, rundnf install sudo(Red Hat family) orapt install sudo(Ubuntu, Debian), 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. The user and its sudo rights still work, as you saw in Step 3. To let alex log in over SSH, open a support ticket and we’ll tell you what we can do.
- sudo shows a different error (for example, it mentions CageFS or LVE, which are parts of CloudLinux): don’t change any settings. Open a support ticket with the exact message.
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.