Creating a New Sudo User on VzLinux
Step-by-step guide to creating a non-root user with sudo access on VzLinux, using the wheel group - the same RHEL-family pattern as AlmaLinux and Rocky.
15 November 2024 4 min read
If you’ve provisioned a new VzLinux VPS, the first thing you should do before anything else is stop using the root account for day-to-day work. Logging in as root for every task is risky – one mistyped command has no safety net. The standard fix, and the same one we recommend for AlmaLinux, Rocky Linux and Oracle Linux, is to create a dedicated user account and grant it sudo privileges via the wheel group. VzLinux, being a RHEL-compatible distribution maintained by Virtuozzo, follows exactly the same pattern.
This guide walks through creating that user, setting a password, adding it to wheel, and confirming sudo actually works before you close your root session.
Before you start
You’ll need root access to your VzLinux server, either via SSH with the root account or through your provider’s console. Everything below is run as root or via an existing sudo user – if this is a fresh VPS, you’re almost certainly starting from a root-only login.
Step 1: Create the new user
Use useradd to create the account. Replace yourusername with whatever you’d like to call it:
useradd yourusername
This creates the user, their home directory at /home/yourusername, and a matching private group, but it doesn’t set a password or grant any special privileges yet.
Step 2: Set a password
Give the account a password with passwd:
passwd yourusername
You’ll be prompted to enter and confirm the new password. Use something strong – if you’re planning to disable password authentication over SSH in favour of key-based login later, this password will still matter as a fallback for console access and for sudo prompts.
Step 3: Add the user to the wheel group
Like every RHEL-derived distribution, VzLinux uses the wheel group to control who can run sudo. Add your new user to it with usermod:
usermod -aG wheel yourusername
The -a flag is important here – it appends the user to the wheel group without removing them from any groups they’re already in. Leave it off and usermod will overwrite their group membership entirely, which is a classic way to accidentally lock yourself out of other permissions.
You can confirm the group membership took effect with:
groups yourusername
You should see wheel listed alongside the user’s own primary group.
Step 4: Verify sudo access
Don’t close your root session yet – verify the new account can actually escalate before you rely on it. Switch to the new user:
su - yourusername
Then confirm sudo works by checking whoami through it:
sudo whoami
You’ll be asked for the user’s password (not root’s) – enter it, and the command should return root. That confirms the user is a member of wheel and that VzLinux’s default sudoers configuration is correctly granting that group sudo access to root.
If you instead get a “user is not in the sudoers file” error, double check the group name was typed correctly and that /etc/sudoers hasn’t been modified to remove the default %wheel entry – on a stock VzLinux install this line should already be uncommented:
%wheel ALL=(ALL) ALL
Step 5: Test SSH access with the new user
Before you disable root login over SSH (which you should, once this is working), open a fresh SSH session as the new user in a second terminal window – don’t close your existing root session until you’ve confirmed it works. This way, if something’s misconfigured, you still have a way back in.
ssh yourusername@your-server-ip
Once you’re confident the account works, you can go ahead and lock down root login in /etc/ssh/sshd_config by setting PermitRootLogin no and restarting the SSH service.
Summary
Creating a sudo user on VzLinux is identical in practice to doing it on AlmaLinux, Rocky Linux or Oracle Linux – useradd, passwd, usermod -aG wheel, then verify with su - and sudo whoami before you trust the account. If you’re new to VzLinux itself and want to understand where it fits compared to the other RHEL rebuilds, see our orientation post on what VzLinux is and when you’d choose it.