Useradd vs Adduser in Linux

PowerADM.com / Linux / CentOS / Useradd vs Adduser in Linux

In Linux, two commands are available to add a new user, useadd and adduser. What is the difference between useradd and adduser, and which one is better to use for creating new users in Linux?

Useradd is a built-in command available in all Linux distros. You can use this command to create a new user or change the settings of an existing one. Try running the command:

# useradd newuser1

This command will create the user and group newuser1. This command doesn’t prompt to set a user password (such a user cannot be used to log in) and doesn’t create a home directory. /bin/sh is assigned as the user’s shell.

In order to create a full-fledged user and set a password, use the commands:

# useradd -d /home/newuser01 -m -s /bin/bash newuser01
# passwd user03

The -m option in this example is used to immediately create the user’s home directory.

Thus, useradd is a low-level command that does nothing without additional parameters. The useradd command is most commonly used to create service accounts, which are used to run services.

The adduser command is an interactive script that creates a user with the settings specified in the /etc/adduser.conf configuration file. This is the easiest and fastest way to add a real user account.

The adduser command is not available on some Linux distributions, sometimes it is a soft link to useradd. On some distributions, this is a Perl script (Debian, Ubuntu, etc.).

Run the command:

# adduser newuser2

What is the difference between useradd and adduser command in Linux?

This command will create user newuser2, home directory, set UID, GID, shell, and some other parameters according to adduser.conf settings. In the end, you will be prompted to set a password. The adduser command is essentially an interactive Perl backend for useradd.

Adduser has additional options. Most commonly used:

  • --system: add a system user. By default, system users are placed in the nogroup group. To add a system user to an existing group, specify the –gid or –ingroup options.
  • --home DIR: use DIR as your home directory instead of the default one. If necessary, a directory will be created and the template files copied.
  • --shell SHELL: set a different SHELL instead of the default.
  • --ingroup GROUP: set user’s primary group.
  • --add_extra_groups: add a new user to the additional group defined in the configuration file.

adduser options

Leave a Reply

Your email address will not be published. Required fields are marked *