Linux adduser command


The adduser command in Linux is a user-friendly tool for creating new users, with additional prompts and options that make it easier to set up user accounts compared to useradd. While useradd is more low-level, adduser is typically more interactive and convenient.

1. Purpose of adduser

adduser is a command-line utility that creates a new user, sets up a home directory, and provides options to configure various account attributes. It’s essentially a wrapper around useradd, with more intuitive options.

2. Using the adduser Command

The syntax for the command is straightforward:

sudo adduser <username>

When you run this command, it:

  1. Creates a new user account with the specified username.
  2. Sets up a home directory for the user (usually /home/username).
  3. Copies default configuration files into the new home directory.
  4. Prompts for a password and additional information like full name, room number, work phone, etc.
  5. Adds the user to any specified groups.

3. adduser Interactive Prompts

After executing sudo adduser <username>, the system will prompt you to:

  • Enter a password: Ensures the user has a password for secure access.
  • Re-enter the password: Confirms the password to avoid typos.
  • Enter additional details: Optionally provides information such as full name, room number, etc., although this is often left blank.

4. Examples of adduser Usage

  • Basic Usage:

    sudo adduser alice

    This command creates a user named alice, prompts for a password, and sets up the home directory and basic configuration.

  • Adding a User to a Specific Group:

    sudo adduser alice developers

    Here, alice is added to the developers group during creation.

5. Customizing adduser with Options

You can customize user creation using options, though many options are available by default through prompts.

For example:

  • Specify a home directory:
    sudo adduser --home /custom/home/path alice
  • Set a default shell:
    sudo adduser --shell /bin/zsh alice

6. Configuration File for adduser

The adduser command’s behavior is also controlled by the configuration file /etc/adduser.conf, where you can set defaults like:

  • Default home directory: Location for user home directories.
  • Default shell: Shell assigned to new users.
  • Default group options: Set group assignments automatically.

7. Differences Between adduser and useradd

While useradd is a low-level utility requiring specific flags for each configuration (e.g., -m for home directory), adduser is a higher-level script that handles these tasks automatically, making it easier and faster to use.

8. Removing Users with adduser

While adduser creates users, it does not handle deletion. To remove a user, you should use deluser:

sudo deluser <username>

The adduser command simplifies user creation with its interactive approach, making it a preferred choice for new and experienced Linux administrators alike.