• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Remover Users in Linux

Winnie Ondara

Published: 5/10/2024

About Terminus

The short answer

In Linux, to remove a user account from the system, you can use the userdel command as follows:

$ sudo userdel <username>

Run in Warp

Where:

  • <username> is the name of the user account you want to delete.

By default, this command will remove the user from the /etc/passwd file, the /etc/shadow file, the /etc/group file, and from any additional groups.

For example, this command will remove the user named alex:

$ sudo userdel alex

Run in Warp

Removing users and their home directory

To remove a user alongside their home directory, including all the files and subdirectories it contains, you can use the userdel command with the -r flag as follows:

$ sudo userdel -r <username>

Run in Warp

Note that this command will also remove the specified user's mail spool.

Alternatively, you can also use the deluser command with the --remove-all-files flag as follows to achieve the same result:

$ sudo deluser --remove-home <username>

Run in Warp

For example, both of these commands will remove the user named alex including their home directory:

$ sudo userdel -r alex
userdel: john mail spool (/var/mail/john) not found

Run in Warp
$ sudo deluser --remove-home alex
Looking for files to backup/remove ...
Removing files ...
Removing user `alex' ...
Warning: group `alex' has no more members.
Done.


Run in Warp

Easily retrieve this command using Warp’s AI Command Suggestions

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:

Thumbnail for

Entering remove user with home directory in the AI Command Suggestions will prompt a deluser command that can then quickly be inserted into your shell by doing CMD+ENTER.

Removing all the files owned by a user

To remove all the files and directories owned by a specified user on the system, outside of their home directory, you can use the as follows:

$ sudo deluser --remove-all-files <username>

Run in Warp

For example, this command will remove all the files belonging to a user named alex:

$ sudo deluser --remove-all-files alex

Run in Warp

Removing a user from a secondary group

In addition to their primary groups, users may often be part of other groups referred to as secondary groups.

To remove a user from a secondary group, you can use the deluser command as follows:

$ sudo deluser <username> <group>

Run in Warp

Where:

  • <username> is the name of the user.
  • <group> is the name of the secondary group.

For example, this command will remove the user named alex from the secondary group named sudo:

$ sudo deluser alex sudo
Removing user `alex' from group `sudo' ...
Done.

Run in Warp

Note that, when executed on the primary group of the user, the userdel command will output the following error:

/usr/sbin/deluser: You may not remove the user from their primary group.

Run in Warp

You can learn more about users and groups by reading our other article on how to create and configure new users in Linux.

Removing a user’s password

To disable the password of a user account, you can remove it using the passwd command with the -d flag (short for --delete) as follows:

$ sudo passwd -d <username>

Run in Warp

This will ultimately allow any other user on the system to log in as that user without using a password.

For example, this command will remove the password of the user named alex:

$ sudo passwd -d alex
passwd: password expiry information changed.

Run in Warp

You can learn more about users and passwords by reading our other article on how to change the password of a user in Linux.

Removing a user from a remote server

To remove a user account from a remote server, you need to first log into the server using the ssh command as follows:

bash 
$ ssh <username>@<server_address>

Run in Warp

Where:

  • <username> is the name of the user you want to log in as on the remote server.
  • <server_address> is the hostname or IP address of the remote server.

Once logged in, you can use the userdel command to delete the specified user as shown in the previous sections.

Written by

Winnie Ondara

Filed Under

Related Articles

List Open Ports in Linux

Learn how to output the list of open TCP and UDP ports in Linux, as well as their IP addresses and ports using the netstat command.

UnixLinux
Thumbnail for Razvan LudosanuRazvan Ludosanu

Count Files in Linux

Learn how to count files and folders contained in directories and subdirectories in Linux using the ls, find, and wc commands.

LinuxUnix
Thumbnail for Razvan LudosanuRazvan Ludosanu

How to Check the Size of Folders in Linux

Learn how to output the size of directories and subdirectories in a human-readable format in Linux and macOS using the du command.

LinuxUnix
Thumbnail for Razvan LudosanuRazvan Ludosanu

Linux Chmod Command

Understand how to use chmod to change the permissions of files and directories. See examples with various chmod options.

Linux
Thumbnail for Razvan LudosanuRazvan Ludosanu

POST JSON Data With Curl

How to send valid HTTP POST requests with JSON data payloads using the curl command and how to avoid common syntax pitfalls. Also, how to solve the HTTP 405 error code.

BashUnixLinux
Thumbnail for Neeran GulNeeran Gul

Format Command Output In Linux

Learn how to filter and format the content of files and the output of commands in Linux using the awk command.

Linux

Create Groups In Linux

Learn how to manually and automatically create and list groups in Linux.

Linux

Switch Users In Linux

Learn how to switch between users, log in as another user, and execute commands as another user in Linux.

Linux

Delete Files In Linux

Learn how to selectively delete files in Linux based on patterns and properties using the rm command.

Linux

Find Files In Linux

Learn how to find and filter files in Linux by owner, size, date, type and content using the find command.

Linux

Copy Files In Linux

Learn how to safely and recursively copy one or more files locally and remotely in Linux using the cp and scp command.

Linux

Create Files In Linux

Learn how to create regular files in Linux using command line interface commands like touch, echo, cat, printf, and in-terminal text editors like Vim.

Linux

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Thumbnail for null