Linux Create User

We will see how to create Linux User. useradd or adduser creates users in Linux. When a new user is created, useradd sets defaults for all fields in /etc/passwd. Username must be unique which means we cant add the user with existing other user names.

useradd command:

  • The useradd command creates a new user account using the values specified on the command line and the default values from the system.
  • The new user account will be entered into the system files (/etc/passwd) as needed, the home directory (/home/username) will be created, and initial files copied, depending on the command line options.
  • useradd does not set any valid password by default and user cannot log in until a password is set.

useradd Syntax:

useradd username [options]

1. Create User in Linux:

To create user with useradd:

useradd george

Then change the user password using passwd.

passwd george

Linux Create User

2. How to create user with specific directory in Linux

If we want to create the user’s home directory other than the default /home directory use the -d option.

useradd karunakar -d /var/karunakar

To verify this,

more /etc/passwd | grep karunakar

Output:

3. How to create user with specific user id in Linux

In Linux, the user id for users created on Linux systems now starts from 1000. On Fedora/CentOS systems it used to be from 500.
Option -u is used to provide specific id.

useradd james -u 5555

To verify this,

4. How to create user with specific Group Id in Linux

When creating a new user the default behavior of the useradd command is to create a group with the same name as the username, and same GID as UID. -G.
-g (–gid) option is used to create a user with a specific initial login group.

useradd ricky -g admins

To verify this,

more /etc/passwd | grep ricky

Where 5556 is the group id of admins.

4. How to create user with multiple groups in Linux

The -G (–groups) option is used specify a multiple groups to the user.

useradd varshi -G admins,sales

So in this article, we have covered how to create Linux user with examples.