> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create delete and modify local user accounts

> Managing local user accounts on Linux for security, privacy, and streamlined administration.

Managing local user accounts on Linux is essential for security, privacy, and streamlined administration. Each user should have a dedicated account so they:

* Keep personal files and directories protected by proper permissions
* Configure their own environment and tool settings
* Operate with the least privilege, reducing accidental damage and attack surface

<Frame>
  ![The image shows a dark interface with the text "Manage Local User Accounts" on the left and a user icon in the center. The word "KodeKloud" is in the top right corner.](https://kodekloud.com/kk-media/image/upload/v1752881493/notes-assets/images/Linux-System-Administration-for-Beginners-Create-delete-and-modify-local-user-accounts/manage-local-user-accounts-interface.jpg)
</Frame>

***

## 1. Creating a New User

Use `useradd` to provision a fresh account.

```bash theme={null}
sudo useradd john
```

By default, this performs:

| Action                | Description                                                          |
| --------------------- | -------------------------------------------------------------------- |
| Create user and group | A new user named `john` and a primary group `john` with matching GID |
| Home directory        | `/home/john` is created and populated from `/etc/skel`               |
| Default shell         | `/bin/bash`                                                          |
| Account expiration    | No expiration date (unlimited)                                       |
| Password              | Unset (must be initialized with `passwd`)                            |

<Callout icon="lightbulb" color="#1CB2FE">
  Skeleton files define initial user config.

  ```bash theme={null}
  ls -a /etc/skel
  # .  ..  .bash_logout  .bash_profile  .bashrc
  ```
</Callout>

You can also review default parameters:

```bash theme={null}
useradd --defaults
# GROUP=100
# HOME=/home
# INACTIVE=-1
# EXPIRE=
# SHELL=/bin/bash
# SKEL=/etc/skel
# CREATE_MAIL_SPOOLS=yes
```

***

## 2. Setting a Password

After account creation, assign a strong password:

```bash theme={null}
sudo passwd john
# Changing password for user john.
# New password:
```

***

## 3. Deleting a User

Remove user accounts carefully:

| Task                                 | Command                                                  |
| ------------------------------------ | -------------------------------------------------------- |
| Delete account (keep home directory) | `sudo userdel john`                                      |
| Delete account + home + mail spool   | `sudo userdel --remove john`<br />`sudo userdel -r john` |

<Callout icon="triangle-alert" color="#FF6B6B">
  Using `--remove` (or `-r`) will delete the user’s home directory and mail spool permanently.\
  Always back up important data before proceeding.
</Callout>

***

## 4. Customizing Account Creation

Pass flags to override defaults:

| Option                    | Description                                     | Example                                   |
| ------------------------- | ----------------------------------------------- | ----------------------------------------- |
| `-d, --home <dir>`        | Custom home directory                           | `sudo useradd -d /home/special_john john` |
| `-s, --shell <shell>`     | Specify login shell                             | `sudo useradd -s /bin/zsh john`           |
| `-u, --uid <UID>`         | Assign specific user ID                         | `sudo useradd -u 1100 smith`              |
| `-g, --gid <GID-or-name>` | Assign primary group (must exist or be created) | `sudo useradd -g 1100 smith`              |

***

## 5. Inspecting User Records

Account metadata resides in `/etc/passwd`:

```bash theme={null}
cat /etc/passwd | grep john
# john:x:1001:1001::/home/john:/bin/bash
```

* Field breakdown: `username:password:UID:GID:comment:home:shell`

View file ownership under `/home`:

```bash theme={null}
ls -l /home/
# drwxr-xr-x 2 john john 4096 Feb  5 10:00 john
```

Display numeric IDs:

```bash theme={null}
ls -ln /home/
```

***

## 6. Identifying the Current User

| Command  | Output                                                |
| -------- | ----------------------------------------------------- |
| `id`     | UID, GID, groups, and SELinux context (if applicable) |
| `whoami` | Current username                                      |

```bash theme={null}
id
whoami
# aaron
```

***

## 7. System Accounts

System accounts serve daemons and services. They typically have UIDs below 1000 and no home directory:

```bash theme={null}
sudo useradd --system sysacc
```

***

## 8. Modifying an Existing User

Use `usermod` to update user settings:

| Change                           | Command                                                      |
| -------------------------------- | ------------------------------------------------------------ |
| Move home directory              | `sudo usermod -d /home/newdir -m john`                       |
| Rename user                      | `sudo usermod -l jane john`                                  |
| Change login shell               | `sudo usermod -s /bin/zsh jane`                              |
| Lock account                     | `sudo usermod --lock jane` `<br />` `sudo usermod -L jane`   |
| Unlock account                   | `sudo usermod --unlock jane` `<br />` `sudo usermod -U jane` |
| Set expiration date (YYYY-MM-DD) | `sudo usermod -e 2022-01-01 jane`                            |
| Remove expiration date           | `sudo usermod -e "" jane`                                    |

***

## 9. Password Aging with `chage`

Control password policies using `chage`:

| Policy                       | Command                 |
| ---------------------------- | ----------------------- |
| Force change on next login   | `sudo chage -d 0 jane`  |
| Reset last password change   | `sudo chage -d -1 jane` |
| Set max days between changes | `sudo chage -M 30 jane` |
| Disable expiration           | `sudo chage -M -1 jane` |
| View aging info              | `sudo chage -l jane`    |

***

## 10. References

* [Linux User Management (The Linux Documentation Project)](https://tldp.org/LDP/sag/html/user-management.html)
* [Kubernetes Basics](https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/)
* [chage Manual](https://linux.die.net/man/1/chage)
* [passwd Manual](https://linux.die.net/man/1/passwd)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/linux-system-administration-for-beginners/module/7e2b6f48-e58c-4d05-82e2-feb0f5f876f5/lesson/d5b36d54-e503-4378-9cb5-e18291372973" />
</CardGroup>
