Linux Commands

What is the difference between useradd and adduser?

Linux comes embedded with many Terminal commands, each having its own purpose. Some of them perform the same function but go about different ways when executing them. Such is the case with adduser and useradd. Both are used for creating a new user but follow different ways to execute it. This article is meant to educate the reader on the key differences between the two commands, with examples on how and when to use them.

Why use adduser and useradd?

To explain why we use adduser and useradd, we first need to understand what Users and Groups are in Linux.

The term User refers to a being or unit responsible for editing, managing, and manipulating files and operations.

A Group refers to a collection of Users that are given special permissions. We can say that a User is analogous to an account, and a Group is a class of accounts with similar permissions.

The commands adduser and useradd are used to create such Users. The main difference is that adduser sets up user folders, directories, and other necessary functions easily, whereas useradd creates a new user without adding the directories as mentioned above and settings.

The adduser command

The adduser command creates a new user and additional information about the user, directories, and a password. Depending on the Command Line options and the given parameters, additional elements can be added. Its syntax is given below:

$ adduser -- options arguments

For example:

$ adduser --help Displays a help window with a list of possible commands

You require special permissions to create a user, i.e., you need to be a superuser. For this purpose, we use the sudo command. Enter as root by running the command given below.

$ sudo -i

The useradd command

The useradd command is used for creating a new user or for modifying the existing user. Unlike adduser, however, it does not create specified directories unless stated otherwise. Useradd also creates a group by default. The syntax for useradd is as follow:

$ useradd [options]

For example:

$ useradd --help Displays a help window with a list of possible commands

To create a new user

$ useradd [options] [username]

Useradd requires options or flags to function properly. Some commonly used flags are given below:

  • -D, –defaults ; Creates new user with default values/sets existing user values to default
  • -c, –comment ; Used to add a string of text.
  • -m ; Used to create a home directory for the new user
  • -G ; Adds a user to additional groups
  • -g ; Displays the group name or group number (GID)
  • -h, –help ; Displays all possible commands
  • -e, –expire ; Used to set the expiry date for the user (YYYY/MM/DD)

Like the case with adduser, useradd also requires certain permissions for creating a new user. Therefore, we use the sudo command under the following syntax:

$ sudo useradd [options] [username]

To set up a password for the new user, use:

$ sudo passwd [username]

Similarities between useradd and adduser

  • Both are Linux terminal commands
  • Both are used to create new users

Differences between useradd and adduser

What separates adduser from useradd is the difference in implementation and execution procedure.

Useradd is an in-built command that comes with all Linux distributions. Adduser comes as a Soft Link or a Perl script and is not available with some Linux distributions. Adduser command utilizes useradd in the backend.

Adduser is a high-level utility command with an easy-to-understand syntax. It prompts the user, asking for information necessary to create a full profile. Upon execution, it guides the user through a step-by-step process to ensure that all directories, groups, and permissions are set according to need.

Adduser automatically sets up the user directory in the home folder.

On the other hand, useradd only executes the command given to it based on the set of flags provided to it, meaning that it will create a user without asking for additional information (passwords, permissions, etc.).

This implies creating a user with all the directories and information, and you need to use multiple flags and options to get the same result you would get from a single adduser command.

Useradd vs. Adduser, which should you use?

Looking back at how both commands work, it is safe to say that adduser should be your preference when creating a new user. Setting up passwords, directories, and groups is cleaner and easier to understand. In most cases, you should be fine by using the adduser command.

This does not mean useradd has no purpose. It offers more flexibility when creating a user. For example, if you need to create a temporary user and do not want to allocate further resources to home directories, groups, etc., you can use the useradd command.

Useradd is also more flexible when it comes to group implementation. You can add the user to multiple groups by using the -G option. The same process would require multiple statements from the adduser.

Being a low-level utility command, useradd would ensure maximum portability across all Linux Distributions.

If you wish to create users without worrying about resource allocation, adduser is the way to go. However, suppose you seek to have more control over what directories and information you want to work with without worrying about portability. In that case, useradd is the command for you.

Conclusion

Both adduser and useradd serve the same purpose, that is, creating a new user. The usage varies based on the requirements of the user. We hope this guide helped you understand the differences between the two, thus sharpening your understanding of essential Linux commands.

About the author

Zeeman Memon

Hi there! I'm a Software Engineer who loves to write about tech. You can reach out to me on LinkedIn.