Void Soul

~/Blogs/Useradd_Process

What happens in the Background when you execute the “useradd” command under Linux

When you execute the “useradd” command to add a new user on the server, in the background, there are several files updated and created. This post lists out the exact steps carried out in the background when you execute the below command.

# useradd john

These Files get affected:

  1. /etc/passwd
  2. /etc/shadow
  3. /etc/group
  4. /etc/gshadow
  5. /etc/gshadow
  6. /etc/skel
  7. /home/username

1. A new line for user john is created in /etc/passwd.

john:x:1001:1001::/home/john:/bin/bash

The new line in /etc/passwd file has the following fields:

2. A new line for john is created in /etc/shadow.

john:!!:17530:0:99999:7:::

The line created in /etc/group has the following characteristics:

3. A new line for a group named john is created in /etc/group.

A group with the same name as a user is called a user private group. When you do not provide a group name explicitly a private group name with the same name as that of the username is created. The fields in /etc/group file are as shown below.

john:x:1001:john

4. A new line for a group named juan is created in /etc/gshadow.

/etc/gshadow contains the shadowed information for group accounts. The line created in the /etc/gshadow file has the following characteristics:

john:!::john

5. User’s home directory is created and files under /etc/skel directory are copied.

A directory for user john is created in the /home directory. This directory is owned by user john and group john. However, it has read, write, and execute privileges only for the user john. All other permissions are denied.

The files within the /etc/skel directory (which contain default user settings) are copied into the new /home/john directory.

Here is a summary flowchart of the steps carried out in the background when a user executes the “useradd” command on a Linux server.

useraddtree

User add process

Credit goes to this source: thegeekdiary