Linux online course

Delete Users in Linux

Learn how to remove local Linux users in Ubuntu and Debian with User Accounts or deluser, while safely retaining or deleting home-directory files.

Removing a Linux user account prevents that account from logging in and using the system. It does not automatically mean that the user's personal files are deleted. On Ubuntu and other Debian-based systems, you can remove a local account through the graphical User Accounts settings or with the deluser command.

This lesson covers local user accounts: accounts stored in the computer's local account database rather than supplied by an external identity service. Account removal changes system-wide account records, so you need administrator privileges, usually through sudo or a root session.

What deleting a Linux user means

A username is the login name used to identify an account. Deleting that account removes the username from the system's account database. The account can no longer normally authenticate, start a new session, or use its previous account permissions.

The account record and the user's files are separate concerns:

  • Delete the account and retain files: the login is removed, but the home directory and its contents remain available for review, archiving, or manual cleanup.
  • Delete the account and remove files: the login and the user's home directory are removed. On Debian-based systems, the user's local mail spool is removed as well when the appropriate deluser option is used.

A home directory is the directory, commonly under /home, that stores personal files and user-specific configuration. Removing it is destructive, so do not select that option until needed data has been backed up.

Before deleting an account

  1. Confirm the exact username. A display name in the graphical interface may differ from the username required by a command. Check the account carefully before proceeding.
  2. Check account details. Use id username to inspect the numeric user identifier, known as the UID, and group memberships.
  3. Check for important data. Determine whether the home directory contains documents, configuration, SSH keys, application data, or other information that must be retained.
  4. Check for active work. The account may own running processes, logged-in sessions, scheduled tasks, or services. Removing an account with active use can fail or disrupt system operations.
  5. Back up required data. Make a copy of important files before choosing an option that removes the home directory.
  6. Confirm administrator access. You need an account authorized to unlock User Accounts or run administrative commands with sudo.

User deletion methods in Ubuntu and Debian

MethodBest forAdministrative authenticationCan retain home filesCan remove home files

Ubuntu User Accounts graphical tool — Beginners who prefer Settings — Unlock with an administrator password — Yes, choose to keep files — Yes, choose to delete files

deluser command — Repeatable terminal administration — Run with sudo or as root — Yes, use the basic command — Yes, use --remove-home

Delete a user with Ubuntu Settings

The exact labels can vary slightly between Ubuntu releases and desktop versions, but the workflow is generally the same.

  1. Open the system Settings application.
  2. Browse the settings categories or search for Users or User Accounts.
  3. Open the user-management page.
  4. Select Unlock, then enter the password for an authorized administrator account. The page may show a lock icon or an unlock control.
  5. Select the local account you want to remove. Confirm that it is the correct username and not the administrator account you are currently relying on.
  6. Choose the remove or minus control. This opens a confirmation dialog.
  7. Choose whether to keep the user's files or delete the user's files. Choose deletion only after backing up anything needed.
  8. Confirm the operation.
  9. Check the user list and verify that the removed account no longer appears.

Delete a user with deluser

deluser is the Debian-family command-line interface for removing user accounts. It is a higher-level front end to the lower-level userdel utility and is generally the preferred administrative interface on Ubuntu and Debian-based systems.

Remove the account but keep its home directory

Use the basic form when the account should disappear but its personal files should remain:

sudo deluser username

Replace username with the confirmed local username. For example:

sudo deluser sam-review

This normally removes the account record while leaving the user's home directory in place. You can then inspect, archive, reassign, or manually clean up the retained files.

Remove the account, home directory, and mail spool

Use --remove-home when the account and its personal data should be removed:

sudo deluser --remove-home username

Example:

sudo deluser --remove-home sam-review

This option is destructive. It removes the account and the user's home directory; it also removes the local mail spool associated with the account. Back up required data first and verify the username before pressing Enter.

What output should you expect?

A successful command may produce only a small status message or little output. Do not treat the absence of an error as your only check. Verify the result afterward.

getent passwd username
id username

After successful removal, getent passwd username should produce no matching account record, and id username should report that the user cannot be found. These checks are also useful before deletion to confirm the exact account name.

deluser and userdel

CommandRoleRecommendationNotes

deluser — Debian-family higher-level account-management front end — Prefer it for normal Ubuntu and Debian administration — Its options and behavior are designed around Debian-family conventions; the basic command normally preserves the home directory.

userdel — Lower-level Linux account-removal utility — Use when following the conventions of a particular distribution or system-management procedure — Options differ from deluser; do not assume that commands and flags are interchangeable.

Both tools can remove account records, but they are not interchangeable without checking the distribution's documentation and option behavior. For an Ubuntu or Debian beginner, deluser is usually the clearer administrative choice.

Choosing what to remove

ChoiceAccount loginHome directoryAppropriate use case

Delete account and retain files — Removed — Kept — The account is obsolete, but files may need review, recovery, or archiving.

Delete account and remove files — Removed — Removed — The account and personal data are no longer needed, and required backups have been made.

Lock or disable instead of deleting — Normal login prevented — Kept — Access should be stopped now, but the account or its files may need to be restored later.

If an account may need to return, locking or disabling it is safer than deleting it. This preserves the account record and files while preventing normal login, depending on the account-management method used.

After deletion

Verify the account is gone

Use a lookup command:

getent passwd username

No matching result is one sign that the account is no longer resolvable. You can also run:

id username

An error indicating that the user cannot be found is expected after successful removal. If you used Settings, verify that the account is absent from the user list as well.

Review files and system roles

Deleting an account does not automatically find and remove every file that the user owned. Files outside the home directory may remain. Linux ownership is stored using numeric UIDs, so such files may display an unresolved numeric owner after the account is removed.

  • Review shared directories and project files.
  • Check scheduled tasks such as user-specific cron jobs or timers.
  • Review services, scripts, and application configurations that used the account.
  • Review group memberships and access arrangements involving the removed account.
  • Decide whether a retained home directory should be archived, reassigned, or removed manually.

Do not blindly delete every file associated with the former UID. Some files may be shared or required by a service. Confirm ownership and purpose before changing or removing them.

Safety and recovery considerations

  • Removing a home directory can permanently destroy personal data. Back up first.
  • Recreating a user with the same username does not necessarily restore the original account settings or file ownership.
  • A replacement account may receive a different UID. Linux permissions use the UID, not only the visible username, so old retained files may not automatically belong to the replacement account.
  • Retaining the home directory allows later recovery, archiving, or deliberate cleanup.
  • Lock or disable an account when access may need to be restored instead of deleting it immediately.

Troubleshooting

The User Accounts page cannot be unlocked

The current account may not be an administrator, or the administrator password may be incorrect. Sign in with an authorized administrator account or ask a system administrator to perform the operation. Similarly, sudo works only for accounts authorized by the system's sudo policy.

deluser says the user does not exist

Check for a spelling mistake and confirm the exact username:

getent passwd username
id username

The account may already have been removed. It may also be managed by an external directory or identity provider rather than as a local account; local deletion tools do not remove externally supplied identities.

The account is removed but files remain

The basic deluser command normally leaves the home directory. Files outside the home directory may also remain regardless of the chosen account-removal method. Archive or remove retained data only after confirming that it is not shared or needed by a service.

Deletion fails because the user is logged in

The account may have active sessions, processes, or services. End sessions and stop relevant processes in a controlled manner, then retry. Avoid terminating a critical service until you understand its role and effect on the system.

A replacement account cannot access retained files

The replacement account may have a different UID even though it has the same username. Inspect numeric ownership and deliberately reassign files only after confirming the intended owner and permissions.

Quick reference

# Check the account before removal
id username
getent passwd username

# Remove the account but normally retain its home directory
sudo deluser username

# Remove the account, home directory, and mail spool
sudo deluser --remove-home username

# Verify after removal
getent passwd username
id username

For related Linux administration lessons, see Linux administration topics.