Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk8 min

How to Add and Delete Users on a CentOS 8 Server Safely

A practical CentOS 8 account-management guide covering user creation, password and SSH considerations, wheel-based sudo, safe deletion choices, verification, troubleshooting, and the platform's end-of-life status.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

On CentOS 8, create a local account with useradd, set its password with passwd, and verify it with id. Add the account to the wheel group only when it needs administrative access. To remove an account while preserving its files, run userdel; to remove the account, home directory, and mail spool, run userdel -r after checking ownership, backups, services, and active sessions.

CentOS Linux 8 reached end of life on December 31, 2021. It no longer receives CentOS Linux content updates, so treat any remaining CentOS 8 machine as legacy infrastructure and include migration to a supported operating system in its operating plan.

As an Amazon Associate I earn from qualifying purchases.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prepare the server before changing an account

Account management requires root access or an account with equivalent sudo permission. Use a maintenance window when the account runs production workloads, and record the change if your organization has audit requirements.

  • Confirm the exact username. A typo in a destructive command can remove the wrong account.
  • Determine whether the account owns systemd services, scheduled jobs, SSH keys, application files, databases, backups, or data outside its home directory.
  • Decide whether the account’s files must be retained, archived, reassigned, or securely removed.
  • Check whether the user is logged in. End the user’s sessions before deletion with sudo loginctl terminate-user <username>.
  • Make any required backup before using a command that removes data.

Do not assume that a user’s home directory contains all of the user’s data. Search for files owned by the account elsewhere on the system and review service definitions, cron entries, timers, and application configuration before changing ownership or deleting anything.

Add a local user on CentOS 8

1. Create the account

Use the standard account utility with the username as its final argument:

sudo useradd <username>

Red Hat documents the general form as useradd <options> <username>. Replace the placeholder, including the angle brackets, with the actual login name. Keep the naming convention consistent with the rest of the host and your organization’s identity policy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some CentOS administration guides use the compatible adduser <username> command. On systems using that behavior, it creates /home/<username> and copies starter files from /etc/skel according to the system defaults. Whichever command style you choose, verify the resulting account instead of assuming a home directory or shell was created exactly as intended.

2. Set a password when local password login is required

sudo passwd <username>

The command prompts for the password twice. Apply the password policy required by your site; the command itself does not define that policy. A local password and an SSH login are separate decisions. If the SSH daemon is configured to reject password authentication, setting a password will not make the account usable over SSH. In that case, install an approved public key and verify the server’s sshd authentication policy separately.

3. Verify the account and its home directory

Run these checks with the same username:

id <username>
getent passwd <username>
ls -ld /home/<username>
  • id displays the numeric user ID, primary group, and supplementary groups. It is the documented Red Hat verification command.
  • getent passwd confirms that the account resolves through the system’s configured account database.
  • ls -ld shows whether the expected home path exists and who owns it.

If the home path is absent, do not create or chown directories blindly. First inspect the account record and the host’s defaults, then correct the configuration according to your local policy.

Give a CentOS 8 user sudo access

Use the administrative wheel group

For full sudo rights through the standard administrative group, append the user to wheel:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo usermod --append -G wheel <username>

The --append option matters: it adds wheel without replacing the user’s existing supplementary groups. Omitting it while supplying a new group list can remove memberships that applications or operations depend on.

Confirm that the wheel rule is enabled

Group membership alone is not authorization. The sudoers configuration must contain an active rule equivalent to:

%wheel ALL=(ALL) ALL

Red Hat’s procedure says to ensure this rule is not commented out. If you need to edit sudoers, use visudo; it checks the syntax before installing the file and helps prevent a malformed policy from locking out administrators.

Test as the target user

sudo -iu <username> sudo whoami

A correctly configured account should print:

root

This test checks the complete path—account resolution, group membership, sudoers policy, and authentication—instead of merely displaying a group list. If it fails, inspect the user’s groups with id <username>, confirm the wheel rule, and start a fresh login session so the new group membership is loaded.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Remove a user but keep the user’s files

Choose this path when the account should no longer authenticate but its home directory, mail, or other data must remain available for review, archival, reassignment, or retention.

1. Stop active sessions

sudo loginctl terminate-user <username>

Before running it, make sure terminating the session will not interrupt a service or an operational task. Investigate and stop user-owned processes or services according to your change procedure.

2. Remove only the account record

sudo userdel <username>

Without the recursive option, userdel removes the account while leaving the user’s files in place. The files may still be owned by the deleted numeric user ID, so preserve an ownership record and decide who should control them. Search outside the home directory for additional files owned by the account before changing or deleting data.

3. Handle retained data deliberately

  • Archive data that must be retained, keeping its permissions and an audit trail where required.
  • Reassign ownership only after a responsible owner and access model have been approved.
  • Review SSH authorized keys, application secrets, job definitions, and service files associated with the former account.
  • Apply the site’s retention and deletion policy rather than deleting retained data as a side effect of account removal.

Remove a user and the home data

Use recursive deletion only after confirming the username and documenting the retention decision:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo userdel -r <username>

The -r form removes the account, its home directory, and its mail spool. It is destructive for those locations and cannot substitute for a backup. It does not mean that every file the user ever owned across the server has been found or removed; investigate files outside the home directory separately.

Account metadata and SELinux cleanup

Red Hat’s fuller RHEL 8 procedure uses:

sudo userdel --remove --selinux-user <username>

Afterward, remove /var/lib/AccountsService/users/<username> when that metadata exists on the host. Whether this path is present depends on the installed components and how the account was managed. Inspect it before removing it, and do not treat the extra cleanup as permission to skip the ownership and service review.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Verify that deletion succeeded

Check account resolution after either deletion method:

getent passwd <username> || echo "account removed"
id <username>

After a successful removal, getent should produce no account entry and the id command should fail. That failure is expected. If either command still resolves the user, check whether the username was entered correctly and whether an external identity source—not the local files—still provides the account.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a retention-preserving removal, separately confirm that the expected files remain and that their future owner and access controls are documented. For recursive removal, verify that the home directory and mail spool are gone, then inspect services, scheduled jobs, SSH configuration, and files outside the home directory for residual references.

Choose the right operation

Goal Command or setting What it changes Important qualification
Create a local account useradd <username> Adds the local account record Verify the home path, shell, and groups rather than assuming defaults.
Set a local password passwd <username> Sets the account’s local password SSH may still reject passwords if sshd policy disables password authentication.
Grant administrative access usermod --append -G wheel <username> Adds the account to wheel Requires an enabled %wheel ALL=(ALL) ALL sudoers rule.
Delete account, retain files userdel <username> Removes the account record Home files and mail remain and need an ownership and retention decision.
Delete account and home data userdel -r <username> Removes the account, home directory, and mail spool Destructive; back up first and confirm the username.
Remove account with fuller RHEL 8 cleanup userdel --remove --selinux-user <username> Performs removal with SELinux-user handling Remove the matching AccountsService metadata path when it exists.

Troubleshoot common failures

The new user cannot connect over SSH

First distinguish local authentication from SSH policy. Confirm that id <username> resolves, that the account has the intended shell and home directory, and that an approved public key is installed if password authentication is disabled. Then inspect the server’s sshd configuration and logs according to your site’s access procedure. A successful passwd command alone does not prove that SSH will accept the account.

Sudo still reports “permission denied”

Check id <username> for wheel membership, confirm that the wheel sudoers rule is active, and test from a newly started session. Use visudo for any policy change. The command sudo -iu <username> sudo whoami should print root when all parts are correct.

The account appears to survive deletion

Run getent passwd <username> and id <username>. If an entry remains, verify the spelling and determine whether the host consults an external identity provider. If the local account is gone but files remain, that is normal after a non-recursive userdel; inspect ownership and retention requirements instead of running recursive deletion after the fact.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Deletion is blocked by running work

Identify the user’s processes, services, jobs, and sessions before terminating anything. Use loginctl terminate-user for active login sessions, then follow your service-management procedure for user-owned workloads. Do not kill an unknown process merely to make userdel complete; determine what it does and preserve data that the service needs.

Operational checklist

  • Root or equivalent sudo access confirmed.
  • Exact username checked against the change request.
  • Services, scheduled jobs, SSH keys, application files, and off-home ownership reviewed.
  • Retention decision and backup completed before destructive removal.
  • Active sessions terminated when deleting an account.
  • New account verified with id, getent passwd, and a home-directory check.
  • Wheel membership tested with sudo -iu <username> sudo whoami when administrative access is required.
  • Post-deletion account resolution checked, and residual files or metadata handled according to policy.
  • CentOS Linux 8 migration tracked because the platform is past end of life.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.