×

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

wget Command in Linux/Unix with Examples

The wget command is a command-line utility in Linux that is used to download files from the internet. It supports various protocols including HTTP, HTTPS, and FTP and can be...

5 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.

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.

top Command in Linux/Unix with Examples

The 'top' command in Linux is a real-time system monitoring tool that displays information about the running processes and system resource usage. The command provides a dynamic, scrolling view of...

4 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.

Linux SCP Command

SCP stands for secure copy protocol. It is a command-line application for copying files and directories safely between two places. Command-line utilities are programs that operate on a computer's command...

3 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.

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.

wc Command in Linux/Unix with Examples

The wc command in Linux is a command-line utility that is used to count the number of lines, words, and characters in a text file or standard input. The name...

4 minutes read.

Rename Folder in Linux

Rename Folder in Linux In the Linux system, there is not any single dedicated command for renaming the files and directories. Mostly, the mv command is used extensively for the purpose...

3 minutes read.

netstat Command in Linux/Unix with Examples

The "netstat" command in Linux is a command-line utility that displays network connections, routing tables, and various network statistics. It is used to display the status of network connections, both...

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.

sed Command in Linux/Unix with Examples

The 'sed' command in Linux is a powerful text processing tool that allows you to perform various operations on text files, such as searching, replacing, and manipulating text. The command...

3 minutes read.

df Command in Linux/Unix with Examples

The 'df' command in Linux is used to display the amount of disk space available on the file system. The command reports the amount of disk space used and available...

3 minutes read.

ping Command in Linux/Unix with Examples

The "ping" command in Linux (and other Unix-like operating systems) is used to test the connectivity between two networked devices. The "ping" command sends a small packet of data, called...

4 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.

Linux mkdir | Linux Create Directory

The Linux mkdir command is very much similar to Windows’s "new folder" feature. This command is used in Linux os to create new directories. The command mkdir stands for "make...

1 minute 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.

Linux ls

The primary use case of the ls command is to list the content available in the directory. The default directory is the current directory of the user. The below screenshot...

5 minutes read.