# Managing users and groups

### I. Users :  <a href="#i.-commands" id="i.-commands"></a>

Most common <mark style="color:yellow;">$COMMANDS</mark> and <mark style="color:yellow;">FILES</mark> used to manage users. consult "<mark style="color:green;">man $command</mark> " for more informations.

#### **Commands :** <a href="#undefined" id="undefined"></a>

* useradd <mark style="color:red;">\<username></mark> -> to add new user.
* userdel <mark style="color:red;">\<username></mark> -> to delete an existed user.
* usermod <mark style="color:green;">-option</mark> <mark style="color:red;">\<username></mark> -> to modify a user characteristics.

**Files :&#x20;**&#x20;

* vim /etc/default/useradd -> <mark style="color:blue;">useradd default config file.</mark>
* vim /etc/passwd | vipw -> <mark style="color:blue;">verify the creation of your user with wanted properties.</mark>
* vim /etc/shadow -> <mark style="color:blue;">stores encrypted user passwords and is accessible only to the root user.</mark>

### II . Groups :

Most common <mark style="color:yellow;">$COMMANDS</mark> and <mark style="color:yellow;">FILES</mark> used to manage groups. consult "<mark style="color:green;">man $command</mark> " for more informations.

#### Commands :&#x20;

* groupadd <mark style="color:red;">\<groupname></mark> -> to create new group.
* groupdel <mark style="color:red;">\<groupname></mark> -> to delete an existing group.
* groupmod <mark style="color:red;">\<groupname></mark> -> modify a group definition on the system.
* lid <mark style="color:green;">-g</mark> <mark style="color:red;">\<groupname></mark> -> display the members of <mark style="color:red;">\<groupname></mark>.
* groupmems -g <mark style="color:red;">\<groupname></mark> -l -> administer members of a user's primary group
* other commands : groups | id | getent group ..

#### Files :

* vim /etc/group | vigr -> <mark style="color:blue;">to list groups in your system.</mark>
* vim /etc/gshadow -> <mark style="color:blue;">readable only by the root user and contains an encrypted password for each grou</mark>

### Configuration files :&#x20;

Let's start explaining the contents of /<mark style="color:green;">etc</mark>/<mark style="color:green;">passwd</mark> "<mark style="color:red;">vipw</mark>" file.

```
chxmxii:x:1000:1000:RHEL8VM:/home/chxmxii:/bin/bash
```

here we took an example of a user called <mark style="color:blue;">chxmxii</mark>. as you can see this line contains 7 fields separated by <mark style="color:green;">":",</mark> I will try to explain it for you one by one.

1. <mark style="color:red;">chxmxii :</mark> is the username.
2. <mark style="color:red;">x :</mark> is the password.
3. <mark style="color:red;">1000 :</mark> User ID.
4. <mark style="color:red;">1000 :</mark> Group ID.
5. <mark style="color:red;">RHEL8VM :</mark> Comment. "GECOS"
6. <mark style="color:red;">/home/chxmxii :</mark> Home Directory
7. <mark style="color:red;">/bin/bash :</mark> shell.

After understanding /<mark style="color:green;">etc</mark>/<mark style="color:green;">passwd</mark>, lets move on and find out what does /<mark style="color:green;">etc</mark>/<mark style="color:green;">shadow</mark> contains.&#x20;

```
chxmxii:$1$KfyGjDYU$OPkmq6g6pFehQk0DxUiZ80:18988:0:99999:7:::
```

Continuing with the same user <mark style="color:blue;">chxmxii</mark>,  unlike "vipw" /etc/shadow contains 9 fields which are :&#x20;

1. <mark style="color:red;">chxmxii :</mark> username
2. <mark style="color:red;">$1$KfyGjDYU$OPkmq6g6pFehQk0DxUiZ80 :</mark> encrypted password using the format *$type$salt$hashed* and eight to 12 characters long.
3. <mark style="color:red;">18988 :</mark> last password change since 1st January 1970.
4. <mark style="color:red;">0 :</mark> The minimum number of days that must elapse before the password can be changed by the user.
5. <mark style="color:red;">99999 :</mark> The number of days after which the password must be changed.
6. <mark style="color:red;">7 :</mark> Warning period.
7. <mark style="color:red;">? :</mark> Inactivity period ( since Jan. 1, 1970).
8. <mark style="color:red;">? :</mark> Expiration date (The date on which the account was disabled.).
9. <mark style="color:red;">? :</mark> This field is left empty and reserved for future use.

{% hint style="info" %}
Sometimes you will find "!" and "!!" within the password field.

"!" means the password is locked.

"!!" means the password is disabled.&#x20;
{% endhint %}

### Hints :&#x20;

* If you want to edit the password quality go to  <mark style="color:green;">"/etc/security/pwquality.conf"</mark> .
* If you want to edit the user configuration go to <mark style="color:green;">"/etc/default/useradd"</mark> .&#x20;
* If you want to edit the umask and pw\.age.. go to <mark style="color:green;">"/etc/login.defs"</mark> .

{% hint style="danger" %}
make sure to create a backup file before editing directly.

f.g : <mark style="color:yellow;">cp /etc/login.defs /etc/login.defs-original</mark>
{% endhint %}

* Created files under <mark style="color:blue;">**/etc/skel**</mark> will be created in <mark style="color:red;">**/home/$USER**</mark> upon creation.

### I . Practice Time:&#x20;

Create user chxmxii with the properties below :&#x20;

* UID : 1544 | GID : 1552 | GECOS : RHELV8 | HomeDir : /home/chxmxii | Shell : /bin/zsh
* make sure chxmxii is a member of wheel group.
* Make sure a file with name "Rules" is created in user home directory upon creation.

#### Answer :&#x20;

```
useradd -u 1544 -g 1552 -c "RHELV8" -d /home/chxmxii -s /bin/zsh chxmxii
usermod -aG wheel chxmxii
touch /etc/skel/Rules
```

{% hint style="success" %}
You have just finished learning users and group managing, lets pass to the next module <mark style="color:blue;">ownerships and permissions.</mark>
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://chxmxii.gitbook.io/rhcsa/managing-users-and-groups.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
