How-to

Create a Sudo User on CentOS Stream, Rocky and AlmaLinux

On the Enterprise Linux family, admin rights come from the wheel group. Four commands give you a personal account that can run anything through sudo.

Which group grants sudo on these systems?

The wheel group. The stock /etc/sudoers on CentOS Stream 9, Rocky Linux 9 and AlmaLinux 9 contains the line %wheel ALL=(ALL) ALL, so every member may run any command as root after typing their own password. The name goes back to old Unix systems, where "big wheel" meant someone with special powers. Debian-family systems use a group called sudo instead, covered in Create a sudo user on Debian.

Which commands set up the account?

Log in as root with the password from the panel, then:

useradd -m -c "Priya, ops" priya
passwd priya
usermod -aG wheel priya
id priya

On these systems useradd creates the home folder by default, but -m makes it explicit and portable. -c stores a comment, handy for knowing who an account belongs to later. id should list 10(wheel). The password set by passwd is what sudo will ask for; make it long, since it is the last line of defense if a session is hijacked.

You can also add the group at creation time with useradd -m -G wheel priya. Either way, the new rights apply at the user's next login.

How do I set up the SSH key?

If your public key was saved in the panel, root received it at install. Copy it over and fix ownership, modes and SELinux labels:

mkdir -p /home/priya/.ssh
cp /root/.ssh/authorized_keys /home/priya/.ssh/
chown -R priya:priya /home/priya/.ssh
chmod 700 /home/priya/.ssh; chmod 600 /home/priya/.ssh/authorized_keys
restorecon -Rv /home/priya/.ssh

The restorecon step is specific to SELinux systems. Files copied from root's folder can keep a label sshd is not allowed to read, which produces a "Permission denied (publickey)" that looks impossible from the modes alone. More on that error in Fix "Permission denied (publickey)".

How do I confirm it works?

Keep the root session open. From your computer, start a new connection as the new user:

ssh priya@203.0.113.25
sudo whoami          # should print root
sudo dnf -y upgrade --refresh

If sudo reports that the user "is not in the sudoers file", either the group change has not been picked up yet (log out and in again) or the %wheel line was commented out. Check with sudo grep -n wheel /etc/sudoers from the root session, and edit only with visudo.

How do I give narrower rights instead?

For an account that should only manage one service, leave it out of wheel and write a drop-in:

cat > /etc/sudoers.d/40-webdeploy <<'EOF'
webdeploy ALL=(root) /usr/bin/systemctl reload nginx, /usr/bin/systemctl restart php-fpm
EOF
chmod 440 /etc/sudoers.d/40-webdeploy
visudo -cf /etc/sudoers.d/40-webdeploy

Rules about safe and unsafe sudo entries are in The sudo command.

What should I do with root afterward?

Restrict root over SSH once the new account is proven. Add PermitRootLogin no to a file in /etc/ssh/sshd_config.d/, run sshd -t and then systemctl reload sshd. Note the unit name: it is sshd on these systems, not ssh as on Debian. You can also lock root's password with passwd -l root; sudo keeps working because it uses the members' own passwords.

Do the three distributions differ here?

DistributionAdmin groupNotes
CentOS Stream 9wheelRolling preview of the next RHEL minor release
Rocky Linux 9wheelRebuild of RHEL 9, identical commands
AlmaLinux 9wheelRHEL 9 compatible, identical commands

All three install free on every x86 and Arm model we sell. Which one to choose is covered on the Rocky Linux, AlmaLinux and CentOS Stream pages.

Can I manage many admins this way?

For a handful, yes: one account and one key per person, all in wheel. Remove a leaver with userdel -r name and their access ends at once. For larger teams, consider central accounts with FreeIPA or an SSH certificate authority, so adding and removing people does not mean touching every machine by hand.

Keep Reading

The sudo command

How sudo decides who may run what, the flags you use daily, safe sudoers rules, logging and the habits that keep root powers contained.

Open

Rocky Linux

Rocky Linux 9, a free Red Hat compatible rebuild focused on staying bug for bug identical to its upstream.

Open

CentOS Stream

CentOS Stream 9 lets you test the next Red Hat minor release early, on a full machine of your own.

Open

SSH root login settings

What each PermitRootLogin value does, how to move daily work to a sudo user and when key-only root login is reasonable.

Open

FAQ

Quick Answers

The wheel group. Members can run any command with sudo after entering their own password.

No. Like Rocky Linux and AlmaLinux it uses wheel; the sudo group belongs to Debian and Ubuntu.

Often the SELinux label on the copied .ssh files is wrong. Run restorecon -Rv on the folder.

sshd. Reload it with systemctl reload sshd after configuration changes.

Remove the user from wheel with gpasswd -d followed by the user name and wheel.