---
title: "Learning the Linux Delete User or Linux Add User Commands"
description: "Account management can be intimidating if you don't know what you're doing. Learn how to manage accounts with Linux delete users or add users with this step-by-step tutorial!"
canonical: "https://adamtheautomator.com/linux-delete-user/"
---

# Learning the Linux Delete User or Linux Add User Commands

> Account management can be intimidating if you don't know what you're doing. Learn how to manage accounts with Linux delete users or add users with this step-by-step tutorial!

Source: https://adamtheautomator.com/linux-delete-user/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Learning the Linux Delete User or Linux Add User Commands](https://adamtheautomator.com/wp-content/uploads/2021/08/Getting-Started-Managing-Users-in-Linux-1.jpg)

# Learning the Linux Delete User or Linux Add User Commands

[![](https://secure.gravatar.com/avatar/2beb65fca997135120ed98dc6a2e57dcdf1a7d7d2f5ff687b5d91dc7ccd7a6b5?s=192&d=mm&r=g)Sagar](https://adamtheautomator.com/author/shanky-mendiratta/)30 August 20216 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Account Management](/tag/account-management/)[Linux](/tag/linux/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Adding a User in Linux](#adding-a-user-in-linux)
*   [Modifying the User Account Expiration Date](#modifying-the-user-account-expiration-date)
*   [Resetting User’s Password](#resetting-users-password)
*   [Changing Account’s Username](#changing-accounts-username)
*   [Managing User Group Membership](#managing-user-group-membership)
*   [Removing a User with Linux Delete User](#removing-a-user-with-linux-delete-user)
*   [Conclusion](#conclusion)

If you are logged into a Linux machine or plan to work as a Linux administrator machine, it’s crucial to know how to manage users, such as with the Linux delete user command, `deluser`. As a Linux administrator, you often need to work with various applications and logs that depend on which user you are using and its permissions.

Lucky for you, in this tutorial, you will learn how to manage Linux users by running various commands in day-to-day activity.

Let’s go!

## Prerequisites

To follow along with this tutorial, it is necessary to have a remote [SSH host](https://en.wikipedia.org/wiki/Secure_Shell). This tutorial uses a Linux distribution, which is [Ubuntu 18.04.5 LTS](https://releases.ubuntu.com/18.04/) with sudo/administration rights.

Related:[How to Set Up OpenSSH on a Windows Server \[Complete Guide\]](https://adamtheautomator.com/openssh-windows/)

## Adding a User in Linux

Before you manage users in Linux, obviously, there must be at least one existing user. So let’s start this tutorial by adding a user to a Linux system.

Related:[A Windows Guy in a Linux World: Users and File Permission](https://adamtheautomator.com/linux-file-permissions/)

1\. Connect to your Ubuntu machine via SSH using your favorite SSH client.

> _You should not use the root user for any activity of the Linux machine because if anything goes wrong, it can corrupt the filesystem or even the operating system._

2\. Next, run the [`useradd`](https://linux.die.net/man/8/useradd) command below to add a user (`shanky`) without a password (`--password`) to the home directory (`-m`) of your Linux system. The `sudo` command runs the command with elevated privileges.

```bash
sudo useradd shanky --password -m
```

3\. Now run the `id` command followed by the user’s name (`shanky`) to verify if the user is properly added to the system.

```bash
id shanky
```

You’ll see a randomly generated **uid, **gid**, and groups** attributes of the user (**shanky**) like in the image below.

![Verifying the New User Exists ](https://adamtheautomator.com/wp-content/uploads/2021/08/Untitled-2021-08-28T141832.544.png)

Verifying the New User Exists

Other than the uid and gid, perhaps you also want to see the home directory of the user you added. If so, run the `cat /etc/passwd | grep shanky` command below. The `/etc/passwd` file contains all user accounts’ information, either already or newly created in the system.

Notice the `grep` command below filters the content of the `/etc/passwd` file to find lines with the word `shanky` in them, then pass the result to the `cat` command to print on the terminal.

```bash
cat /etc/passwd | grep shanky
```

You can see in the screenshot below that a home directory (**/home/shanky**) exists for the user named **shanky**, which indicates the user exists.

![Verifying User Existence](https://adamtheautomator.com/wp-content/uploads/2021/08/Untitled-2021-08-28T142032.905.png)

Verifying User Existence

## Modifying the User Account Expiration Date

Now that you have created at least one user, let’s start managing the user, like modifying the user account expiry. The user account expiry is the date when a user account will expire. There are times you need to modify an account expiry for users for a specific purpose, such as the account expired earlier than expected or as per user’s request.

Before modifying the user account’s (shanky) expiry, first, check the current expiry date.

To check the account’s expiry date, run the [`chage`](https://linux.die.net/man/1/chage) command below. The `chage` command lists user’s account information and modifies passwords and accounts expiry dates by default. For this example, the `-l` option is added to list the user’s (`shanky`) information.

```bash
chage shanky -l
```

You can see below that the account’s expiry date is Jan 01, 1970

![Listing User's Information to see Account Expiry Date](https://adamtheautomator.com/wp-content/uploads/2021/08/expiry.png)

Listing User’s Information to see Account Expiry Date

Now let’s see a quick example of changing a user account’s expiry.

Run the `chage` command below to change user’s (`shanky`) account expiry (`-E`) to September 01, 2021 (`2021-09-01`).

```bash
chage shanky -E 2021-09-01 # Expiry date format: YYYY-MM-DD
```

> _Note that user account expiry is different from password expiry. Password expiry is the date when the current password will no longer work. To modify a user account’s password expiry date instead, replace the `-E` option with the `-M` option, then set the maximum days before the password expires. The complete command would be like this: `chage shanky -M 30`_

List the user’s information as you previously did to see the user account’s new expiry date. As you see below, the new account expiry date is set to **Sep 01, 2021**.

![Listing User's Information to see New Account's Expiry Date](https://adamtheautomator.com/wp-content/uploads/2021/08/new-expiry.png)

Listing User’s Information to see New Account’s Expiry Date

## Resetting User’s Password

Earlier, you learned how to modify a user’s account and password expiry option, but it’s also important to learn how to reset a user’s password before it expires. Regularly resetting or changing a user account password helps secure a user’s password from exposing it to attackers. Or due to the most common reason, the user forgot the password.

To reset a user’s password, run the `sudo passwd shanky` command below. The `passwd` command alone lets you change a user’s password, but the function changes when you put additional options with it. For example, if you add the `-d` option, the `passwd` command deletes the user’s password, like this: `sudo passwd -d shanky`.

```bash
sudo passwd shanky
```

Enter and confirm the new password in the prompts, as shown below. Once done, you’ll get a message that says **passwd: password updated successfully**.

![Resetting a User's Password](https://adamtheautomator.com/wp-content/uploads/2021/08/password-reset.png)

Resetting a User’s Password

## Changing Account’s Username

Earlier, you performed lots of activity with an account named “shanky,” which is the account’s username. There are times when you need to change an account’s username, like when they change their name in the organization or as part of account security.

Run the [`usermod` command](https://man7.org/linux/man-pages/man8/usermod.8.html) below to change the account’s (`shanky`) username to `shankyo`. The `usermod` command modifies account files based on the changes you specified when you run the command.

```bash
sudo usermod -l shankyo shanky
```

Now run the `id` command followed by the user’s name (`shankyo`) to verify if the username is changed.

```bash
id shankyo
```

Below, you can see that the user’s login name is now set to **shankyo.**

![Verifying if the User's Login Name is Changed](https://adamtheautomator.com/wp-content/uploads/2021/08/id.PNG.png)

Verifying if the User’s Login Name is Changed

## Managing User Group Membership

Changing a user’s login name is a sensitive task. What if you mistakenly added a user to a group with special permissions? How would you remove the user from that group? Don’t worry; the [`gpasswd` command](https://man7.org/linux/man-pages/man1/gpasswd.1.html) [](https://man7.org/linux/man-pages/man1/gpasswd.1.html)will do the trick. The `gpasswd` command lets you administer groups in your Linux system.

Whenever you add a new user (shanky), the system automatically adds that user to a group with the same name (shanky) by default. You previously changed an account’s username from “shanky” to “shankyo,” but that user’s account remains in the “shanky” group. As a result, the user (`shankyo`) still benefits from the “shanky” group’s permissions.

1\. Run the `gpasswd` command below to remove (`-d`) the user (`shankyo`) from the group named `shanky`.

```bash
sudo gpasswd -d shankyo shanky
```

2\. Next, run the [`groupadd`](https://man7.org/linux/man-pages/man8/groupadd.8.html) command below to create a group named `shankyo` in the _[/etc/group](https://www.cyberciti.biz/faq/understanding-etcgroup-file/)_ file since the group doesn’t exist yet. The _/etc/group_ file is a text file where groups are defined, one entry per line. The `groupadd` command creates a new group account based on the values you specified on the command.

```bash
groupadd shankyo
```

3\. Finally, run the `usermod` command below to add the user (`-a shankyo`) to the group (`-G shankyo`). And then, run the `[groups](https://man7.org/linux/man-pages/man5/group.5.html) shankyo` command to return the group(s) that the user (`shankyo`) belongs to.

```bash
# Adds the user named 'shankyo' to the shankyo group
sudo usermod -a shankyo -G shankyo
# Returns the group(s) that the user named 'shankyo' belongs to
groups shankyo
```

![Viewing Groups the User Account Belongs to](https://adamtheautomator.com/wp-content/uploads/2021/08/groups.PNG.png)

Viewing Groups the User Account Belongs to

## Removing a User with Linux Delete User

Now you have learned how to add and modify a user’s account, which is good enough to manage a user’s account. But perhaps a user account is not in use anymore or was added by mistake. In that case, the [`deluser`](https://www.commandlinux.com/man-page/man8/deluser.8.html) command is what you need. The `deluser` command removes users and groups from the system according to the options you specify in a command.

Run the `deluser` command below to delete all files owned (`--remove-all-files`) by the user account (`shankyo`) from your Linux system. The command removes the user account’s (`shankyo`) home directory and [mail spool](https://ostoday.org/linux/question-what-is-mail-spool-in-linux.html) and removes the user from the _/etc/passwd_ and _[/etc/shadow](https://man7.org/linux/man-pages/man5/shadow.5.html)_ files. The _/etc/shadow_ file contains information about the system’s account’s password.

```bash
sudo deluser --remove-all-files shankyo
```

Now run the `id` command, followed by the user’s login name (`shankyo`), to verify if the user is deleted from the system.

```bash
id shankyo
```

Below, you can see the message that says **id: ‘shankyo’: no such user**.

![Verifying the User Account is Removed](https://adamtheautomator.com/wp-content/uploads/2021/08/shankyo.png)

Verifying the User Account is Removed

## Conclusion

In this tutorial, you learned how to add, manage and delete users, one of the many joys of being a Linux system administrator. You’ve also learned how to secure a user account by changing user’s login name and resetting a user’s password.

Now how would kick this newfound knowledge up a notch? Perhaps automating the password reset when a user’s password expires?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Flinux-delete-user%2F&text=Learning%20the%20Linux%20Delete%20User%20or%20Linux%20Add%20User%20Commands)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Flinux-delete-user%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Flinux-delete-user%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2022/09/Practical-Linux-Unix-Tee-Commands-for-the-Linux-Admin.jpg)

### [Master Unix tee Commands for Real-World Linux Admin Tasks](/unix-tee/)

Simplify Linux output management and streamline your workflow with the “Unix tee” command. This tutorial guides you through its practical applications.

![](https://adamtheautomator.com/wp-content/uploads/2024/03/openldap-4.jpg)

### [How to Install and Configure an OpenLDAP Ubuntu Server](/openldap/)

Unlock the power of OpenLDAP on Ubuntu for centralized user authentication, seamless access control management, and enhanced directory services!

![](https://adamtheautomator.com/wp-content/uploads/2024/03/pipe-command-in-linux-1.jpg)

### [Unleashing the Power of the Pipe Command in Linux](/pipe-command-in-linux/)

Unlock the prowess of the pipe command in Linux to streamline tasks, boost productivity, and simplify complex operations effortlessly!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
