# How to use the Linux useradd command

The Linux useradd command does exactly what its name suggests, it adds users. [Linux](https://www.ionos.com/digitalguide/server/know-how/linux-the-cost-effective-alternative-to-windows/ "Linux – the cost-effective alternative to Windows") also has other commands to carry out this task meaning you have several options available to you.

## What is the Linux useradd command?

The [Linux command](https://www.ionos.com/digitalguide/server/configuration/linux-commands-an-overview-of-terminal-commands/ "Linux commands: An overview of terminal commands") useradd is one of your many options if you want to **add a new user via the terminal**. While various [Linux distributions](https://www.ionos.com/digitalguide/server/configuration/linux-distributions/ "Linux distributions") such as [Ubuntu](https://www.ionos.com/digitalguide/server/know-how/ubuntu-the-linux-system-for-everyone/ "Ubuntu: The Linux system for everyone") use this command because it’s not interactive and tends to experience fewer problems, the command adduser is often more secure. Alternatively, you can also add new users via a graphical program. Read on for an explanation of how to use the useradd command without any issues.

## How does the useradd command work?

Linux useradd can only be used by those who have root rights or [Linux sudo command](https://www.ionos.com/digitalguide/server/configuration/linux-sudo-command/) privileges. The values for the command are **set in the file /*etc*/*default*/*useradd***. Based on these parameters, the system creates a new user with a selected name. Additionally you can use the useradd command to set passwords for new users. We explain how to do it below.

## What does the useradd syntax look like?

The syntax for useradd looks as follows:

```shell
$ useradd [Options] [Username]
```

If you don’t add any additional options, the system will simply create a user with the name you enter.

## What options does the useradd command have?

Linux useradd has numerous options. These are the most important:

- **-d:** Here you set the start directory of the new user.
- **-e or --expiredate:** Sets when the new account will expire, if you don’t enter anything it will never expire.
- **-f:** Sets when an account will expire when the password belonging to it expires.
- **-g:** Sets the user group the new user primarily belongs to.
- **-m:** Creates the home directory of the new account if one currently doesn’t exist.
- **-p or --password:** Set the password for the new account. However, for security reasons, the [passwd command](https://www.ionos.com/digitalguide/server/configuration/linux-passwd-command/) is better suited for this.
- **-s:** Sets the standard login shell for all new accounts.

## Examples of a useradd command

Finally you can see some examples of how to use the Linux useradd command:

```shell
$ sudo useradd testuser
```

Creates the new user *testuser*.

```shell
$ sudo useradd -m testuser
```

You can use this command to create a new home directory for *testuser*.

```shell
$ sudo useradd -e 2023-12-31 testuser
```

This command creates an account for *testuser* which will be deactivated on December 31st, 2023.


This is a markdown version of: [https://www.ionos.com/digitalguide/server/configuration/linux-useradd-command/](https://www.ionos.com/digitalguide/server/configuration/linux-useradd-command/) for AI/LLM consumption.