Hurry! Try our new Interactive Courses for FREE. 🥳   🚀

How to Add User in Linux?

In Linux, for adding a new user, we can use useradd command.

We know that Linux/Unix is a multiuser operating system it means multiple users can interact with the system at the same time. User management is the system administrator's responsibility that how it should be managed related tasks like create a new user remove existing user and so on. The useradd command is used to create a new user in the Linux system.

User management task performed by root or sudo privileges. If we use the useradd command with the sudo privileges then we have to provide the system password.

The general syntax of the useradd command.

useradd [options] LOGIN
useradd -D
useradd -D [options]

Brief description of options available with the useradd command.

Options Description
--badnames do not check for bad names
-D, --defaults print or change default useradd configuration
-G, --groups GROUPS list of supplementary groups of the new account
-m, --create-home create the user's home directory
-o, --non-unique allow creating users with duplicate (non-unique) UID
-r, --system create a system account
--help display help and exit

Example: Adding a new user to the Linux operating system

In this example, using sudo useradd <username> command we can easily add new users to our system. Here we are not executing this command with the root privilege so we need to use sudo and we have to provide a system password.

sudo useradd avenger

Example: Display the current default options type using -D or --default option

In this example, after execution useradd --default or useradd -D the current default options will be prompt as shown in the below picture.

useradd --default

Example: Creating a system user using -r or --system option with useradd command.

In this example, we can create a system user using sudo useradd --system <username>. The major difference between the system user and the normal user is, system users is created with no expiry date.

creating system user

In the options table, only a few important option and description is given to know more about options available in useradd command user useradd --help it will prompt all available options in the useradd command.

useradd --help