×

adduser Command in Linux with Examples

What is the adduser command?

The adduser command creates a new user, and this command may be used to add apre-existing user to a group that already exists.

How to use the adduser command to create a new user?

  1. Adding a normal user: When we use the adduser command without the --group or --system options and with one non-option argument, a normal user is added. The first UID is chosen from the range declared for normal users in the configuration file by the adduser command. If you want, you can override UID using the –uid option. Similarly, the range declared in the configuration file can be overridden using the –firstuid and –lastuid options. To set VERBOSE i.e., the environment variable, the following rules should be kept in mind:
    • --quiet option is defined.
    • --debug option is defined
    • or neither of --quiet nor --debug is defined
  2. Adding a system user: To add a system user, the adduser command has to be called with the --system option and one non-option argument. If already a user exists with the same name then the adduser command returns with a warning. If you want to suppress the warning, you may use the --quiet option.
  3. Adding an existing user to a group that already exists: If the adduser is run with two non-option arguments then the user is added to a group if it already exists.

Syntax:

adduser [--system][--firstuidID] [--home DIR] 
[--shell SHELL] [--no-create-home]
        [--uidID] [--lastuidID]
        [--ingroup GROUP | --gid ID] 
[--disabled-password]
        [--gecosGECOS] [--add_extra_groups]
        [--encrypt-home] [--quiet] [--debug] 
[--force-badname]
        [--help|-h] [--version] [--conf FILE] user


adduser [options] usergroup

Explanation of some options used in the above line code:

--conf FILE    This option use FILE in place of /etc/adduser/conf.
--disabled-loginThis option makes the user set a password for his account, or else he would not be able to use his account.
--disabled    password     This option is similar to –disabled-login, but the user can log in to his account without using a password.
--force-badnameThe user and group names are checked, by default. So, this option pressures adduser and addgroup to check roughly for the cogency of the name.
--gecos GECOSThis option will restrict the adduser to ask for finger information.
--gid IDWhen this option is used, the given number is forced to be the new group ID. If a user is created/added, due to this option he is added to that group.
--group         If we want to create the group with the same name as the system user, we combine this option with the --system. The group with the given name is created, if this option is not combined with the --system.
--helpThis option is used to show a help message and exit.
--home DIR  If we use DIR as the user’s home directory, then if the directory does not exist, it is created and the skeleton files are copied.
--quiet           This option only displays errors and warnings and hides informational messages.
--systemThis option creates a system group or system user.
--add_extra_groupsThis option adds a new user to extra groups.
--versionThis option shows copyright information and version.

Configuration:

The defaults for the programs are held by the file /etc/adduser.conf. A single value pair exists in every line, in the form “option = value”. A hash sign (#) is compulsory in a comment line.

Some of the valid configuration options are:

DSHELLThis is the log-in shell, that is used for all users. Reverts to /bin/bash.
DHOMEThis is the directory where the new home directories have to be created. Reverts to /home.
GROUPHOMESThe home directory is created as “/home/[groupname]/user” if set to yes. Reverts to no.
SKEL   This is the directory from which the user configuration files have to be copied. Reverts to /etc/skel.
LETTERHOMESThe home directories have an extra directory added that is the first letter of the login name if this is set to yes.

Files:

/etc/adduser.confIt is a revert layout for adduser and addgroup.

Working on addgroup command in Linux

  1. For adding a new user, we use:
adduser username
adduser command in linux with examples

To add a new user, we use the above command. You will just have to enter some required details and after that, a new user account will be created.

  • For adding a user with a different shell, we use:
sudo adduser username --shell /bin/sh
adduser command in linux with examples

If you want to change the default shell, this command can be used. It will change it to /bin/sh.

  • For adding a user with a completely different configuration file, we use:
adduser username --conf custom_config.conf
adduser command in linux with examples

After using this command, it will take configurations from the custom-coding file, and the new configurations will be created according to the custom-coding file configurations.

  • For adding a user with a different home directory, we use:
adduser username --home /home/manav/
adduser command in linux with examples
  • For displaying the version of the adduser command, we use:
adduser –version
adduser command in linux with examples
  • For showing the help section of the adduser command, we use:
adduser -h 
adduser command in linux with examples

Related Topics

tar Command in Linux/Unix with Examples

The 'tar' command in Linux is used to create, maintain, and extract files from archive files called tarballs. The command stands for "tape archive" and it allows you to combine...

4 minutes read.

Difference Between Linux and Windows

Linux vs. Windows Here in this tutorial, we are going to discuss several features of Linux and Windows. These features or characteristics help us to come to a conclusion about which...

5 minutes read.

gzip Command in Linux/Unix with Examples

The gzip command in Linux is used for compressing and decompressing files. It uses the Lempel-Ziv coding (LZ77) algorithm to compress files, which is known for its high compression ratio...

6 minutes read.

touch Command in Linux/Unix with Examples

The "touch" command in Linux (and other Unix-like operating systems) is used to create new empty files or update the timestamps of existing files. The touch command is a simple...

4 minutes read.

ssh Command in Linux/Unix with Examples

The ssh (Secure Shell) command in Linux is used to remotely access and control another computer or device over a network. It provides a secure and encrypted connection between the...

6 minutes read.

Difference Between Unix and Linux

Unix vs Linux Unix and Linux both have been of great use in changing the world of operating systems. Unix was among the very few operating systems which were programmed for...

4 minutes read.

man Command in Linux/Unix with Examples

The man command in Linux is used to display the manual pages for a given command or system call. These manual pages provide detailed information on the command's usage, options,...

3 minutes read.

tail Command in Linux/Unix with Examples

The "tail" command in Linux (and other Unix-like operating systems) is used to display the last few lines of a file. By default, the tail command will display the last...

4 minutes read.

Linux Bash

Linux Bash In this tutorial, we are going to learn what the shell is? And how many various shells we have, we have also covered most of the bash shell features....

4 minutes read.

cd Command in Linux/Unix with Examples

The 'cd' command in Linux is used to change the current working directory. The command stands for "change directory" and it is used to navigate the file system on a...

3 minutes read.

sudo Command in Linux/Unix with Examples

The sudo command in Linux is used to run a command or set of commands with the privileges of another user, typically the root user. This allows users to perform...

3 minutes read.

Linux Commands with Examples

Linux Commands with Examples All the Linux commands are executed on the terminal provided by the Linux system. This terminal is a command-line interface to implement and display command outputs. Linux...

10 minutes read.

addr2line Command in Linux with Examples

Use of addr2line Command The addr2line command is used to convert addresses to line numbers and file names. This command uses debugging info to check which line number and file name...

4 minutes read.

cat Command in Linux/Unix with Examples

The cat command in Linux is a command-line utility that is used to display the contents of a text file. It stands for "concatenate" and it is used to view...

4 minutes read.

adduser Command in Linux with Examples

What is the adduser command? The adduser command creates a new user, and this command may be used to add apre-existing user to a group that already exists. How to use the...

4 minutes read.

rm Command in Linux/Unix with Examples

The "rm" command in Linux (and other Unix-like operating systems) is used to remove files and directories. The "rm" command stands for "remove" and it is used to delete files...

4 minutes read.

Linux rmdir command

The default use case of the rmdir command in the Linux system is to delete an empty directory. The below screenshot shows how to delete the empty directory. First, we...

1 minute read.

mv Command in Linux/Unix with Examples

The 'mv' command in Linux is used to move or rename files and directories. The command stands for "move" and it allows you to move files and directories from one...

3 minutes read.

Linux apt-get command

Apt-get is a command-line that helps to handle the packages in Linux. Its major task is to assist in retrieving data and packages from trusted sources for purposes of installation,...

6 minutes read.

Linux Path Completion

Every operating system has some features which make them special. The Linux operating system primarily works on the command line interface, and we do have many features for this CLI....

1 minute read.