How To Use adduser or useradd Command In Linux

adduser or useradd is a very useful command in Linux to allow users creating user accounts in system with some specific privileges, limitations and so on. Technically, useradd is a utility which can be used for creating or adding new user account un Unix like operating systems. The term adduser command or useradd, both is similar as they are just symbolic links.

When dealing with adduser command in Linux platforms, a user should be aware of differences which is obvious due to different OS platforms or versions. It’s better to check the corresponding documentation for more details regarding how to create new user accounts with this command.

When this command runs it do a number of things inside the operating system, which are as follows:

  • alters files within directories (/etc/passwd, /etc/shadow, /etc/group and /etc/gshadow) for new user accounts.
  • Creates and assigns a new home directory for new user.
  • Assigns permissions along with ownerships to home directory.

How to install adduser command in Linux platforms?

Based on various Linux distributions, the users can run the following commands to install adduser command on their system.

Debian/Ubuntu users

sudo apt-get install adduser

Centos/RedHat users

sudo yum install adduser

Fedora users

sudo dnf install adduser

Examples to use adduser command

1: To create a new user

sudo adduser servonode

Explanation: Running this command with add a new user servonode to Linux system. When executed, the users will be asked for inputs like full name, address, contact details, etc. Once these information are fed, the new user will be created.

2: Adding user with another shell

sudo adduser servonode --shell /bin/sh

Explanation: This command will also run similarly to one described in example 1, but the default shell for the user will be changed to a directory specified. It will also ask some information as above.

3: Adding new user with another configuration file

sudo adduser servonode --conf custom_config.conf

Explanation: With this command, a new user will be created with another configuration file specified in the command (custom_config.conf).

4: Adding new uesr with another home directory

adduser servonode --home /home/sn/

Explanation: Running the above command will create a user servonode with a new home directory.