×

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.

ls Command in Linux/Unix with Examples

The ls command in Linux is a command-line utility that is used to list the files and directories in a directory. It is one of the most basic and commonly...

4 minutes read.

scp Command in Linux/Unix with Examples

The scp (secure copy) command in Linux is a command-line utility that is used to securely transfer files between two hosts over a network. It is similar to the cp...

4 minutes read.

Linux Commands List

Linux Commands List The Linux systems are filled with commands for several use cases. We have divided these commands into some of the most common implementations for a better understanding of...

2 minutes read.

How to change the ApacheHTTP port in Linux

What is an Apache HTTP server in Linux? When we talk about the most commonly used web servers, one of the web servers that cannot be missed is Apache. With the...

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

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 Absolute and Relative Path

The concept of the absolute and relative path is very simple. The names “relative path” and “absolute path” give us little understanding of the concept we are learning here. The...

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

addgroup Command in Linux with Examples

What is the addgroup command? It is a command in Linux to create a new group using specified command lined and the system’s default values. How to add groups Adding a user group:...

4 minutes read.

chown Command in Linux/Unix with Examples

The 'chown' command in Linux is used to change the ownership of a file or directory. The command stands for "change owner" and it allows you to change the user...

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

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.

echo Command in Linux/Unix with Examples

The "echo" command in Linux is used to display a line of text on the terminal. It can also be used to print the value of a variable or to...

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.

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 Command in Linux/Unix with Examples

The rename command in Linux is used to rename multiple files at once, using a specified pattern. The command is also known as rename, ren, and mv. This command is...

3 minutes read.

ps Command in Linux/Unix with Examples

The 'ps' command in Linux is used to display information about the running processes on a system. The command stands for "process status" and it allows you to view details...

4 minutes read.

mkdir Command in Linux/Unix with Examples

The "mkdir" command in Linux (and other Unix-like operating systems) is used to create new directories. The "mkdir" command stands for "make directory" and it is used to create a...

3 minutes read.

Linux cd

Linux cd: As in GUI operating systems like Windows 10, we use the mouse to travel to various folders back and forth; similarly, we have the “cd” command in Linux...

4 minutes read.