> For the complete documentation index, see [llms.txt](https://devops-3.gitbook.io/devops/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devops-3.gitbook.io/devops/docs/module-1-linux-introduction/users.md).

# Users

A user is an entity, in a Linux operating system, that can manipulate files and perform several other operations. Each user is assigned an ID that is unique for each user in the operating system.

After installation of the operating system, the **ID 0 is assigned to the root user** and the IDs 1 to 999 (both inclusive) are assigned to the system users and hence the ids for local user begins from 1000 onwards.&#x20;

In a single directory, we can create 60,000 users.

<figure><img src="https://921544542-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FiRQTWHUNVZ5tIxQJXclF%2Fuploads%2F6F5ZDWCSMSh6HH5bPlOC%2Fuser-management-in-linux_thumbnail.webp?alt=media&amp;token=16856206-5328-4037-9cf3-38528f9ee2aa" alt=""><figcaption><p>User Management</p></figcaption></figure>

Now we will discuss the important commands to manage users in Linux.

1. AWK command

To **list out all the users in Linux**, use the awk command with -F option. Here, we are accessing a file and printing only first column with the help of *print $1* and *awk*.&#x20;

```bash
awk -F':' '{ print $1}' /etc/passwd 
```

2. ID command

Using id command, you can get the ***ID of any username***. Every user has an id assigned to it and the user is identified with the help of this id. By default, this id is also the group id of the user. &#x20;

```bash
id username
```

3. Useradd command

The command to add a user. *useradd command* adds a new user to the directory. The user is given the ID automatically depending on which category it falls in.&#x20;

The username of the user will be as provided by us in the command.&#x20;

```bash
sudo useradd username
```

4. Password command

Using passwd command to assign a password to a user.&#x20;

After using this command we have to enter the new password for the user and then the password gets updated to the new password. &#x20;

```bash
passwd username
```

5. User Configuration

This commands prints the data of the configuration file. This file contains information about the user in the format.

```bash
cat /etc/passwd
```

6. Usermod command

The command to **change the user ID for a user**. &#x20;

```bash
usermod  -u new_id username
Ex: sudo usermod -u 1982 user1
```

7. Change User Login Name command

You can **change the user login name** using *usermod* command. The below command is used to change the login name of the user.&#x20;

The old login name of the user is changed to the new login name provided. &#x20;

```bash
sudo usermod -l new_login_name old_login_name
```

8. User Directory setup command

The **command to change the home directory**.&#x20;

The below command change the home directory of the user whose username is given and sets the new home directory as the directory whose path is provided

```bash
usermod -d new_home_directory_path username
```

9. Delete user

You can also **delete a user name**. The below command deletes the user whose username is provided.

```bash
userdel -r username
```

10. &#x20;User Database Files

{% code overflow="wrap" %}

```bash
/etc/passwd — → this file contains all user details as a list.
```

{% endcode %}

{% code overflow="wrap" %}

```bash
/etc/shadow — → this file contains all user password details as a list.
```

{% endcode %}

{% hint style="info" %}
User and group management in Linux is vital for maintaining security and access control.
{% endhint %}
