هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
أهداف الامتحان في هذا الفصل
- إنشاء حسابات المستخدمين المحليين وحذفها وتعديلها
- تغيير كلمات المرور ومدة صلاحيتها للمستخدمين المحليين
- إنشاء المجموعات المحلية وأعضائها وحذفها وتعديلها
- إعداد صلاحيات الإدارة (privileged access)
Know the kinds of users
Linux knows three kinds of accounts. The UID (user ID number) tells which one it is.
| Kind | UID | Example | Use |
|---|---|---|---|
| root | 0 | root | Full control of the system |
| System accounts | 1–999 | apache, chrony, sshd | Run services; nobody logs in with them |
| Normal users | 1000+ | student | People |
تذكّر
UID 0 = root, under 1000 = services, 1000 and up = people.
Work as root only when you need it
root can do anything — also destroy the system with one typo. Work as a normal user and switch to root only for admin tasks.
- The prompt shows it:
$for a normal user,#for root. - Use
sudo COMMANDfor one admin command, orsudo -ifor a root shell when you have many tasks. - Leave the root shell with
exitas soon as you are done.
في العمل
Every sudo command is logged in /var/log/secure (and the journal) with the real user name. A shared root password has no such trace.
Switch user with su
su (substitute user) starts a shell as another user. You type that user's password.
su -(with the dash) gives a full login shell: the new user's environment and home folder. Always use the dash.suwithout a user name means root.- root can switch to any user without a password.
انتبه
su without - keeps your old environment (PATH, variables). Programs can behave strangely or run from the wrong folder.
Give admin rights with sudo
sudo lets allowed users run commands as root (or another user) with their own password. The rules are in /etc/sudoers and in files in /etc/sudoers.d/.
On RHEL, members of the group wheel may run everything:
%wheel ALL=(ALL) ALL- Give a user full admin rights by adding the user to wheel.
usermod -aG wheel lisa - Or give one user only some commands, in a separate file. Always edit with
visudo, which checks the syntax before saving.visudo -f /etc/sudoers.d/webadmins/etc/sudoers.d/webadmins%webadmins ALL=(root) /usr/bin/systemctl restart httpd, /usr/bin/systemctl status httpd - Test it as that user.
The rule format is: WHO WHERE=(AS_WHOM) COMMANDS. A % before the name means a group. NOPASSWD: before the commands means no password is asked.
نصيحة للامتحان
The objective "configure privileged access" = sudo rules. Use a file in /etc/sudoers.d/ and visudo; never break /etc/sudoers.
انتبه
A syntax error in a sudoers file can lock everybody out of sudo. visudo stops you before you save a broken file.
Know PolicyKit
PolicyKit (polkit) decides which actions of system services a user may do — for example change the network, shut down, or mount a disk — mostly from graphical tools.
- When a user without rights tries such an action, polkit asks for an admin password.
- Members of
wheelcount as administrators for polkit. pkexec COMMANDruns a command as root through polkit (like sudo, but with polkit rules).- Rules are in
/usr/share/polkit-1/(do not change) and/etc/polkit-1/rules.d/(your own).
Read /etc/passwd and /etc/shadow
User accounts are lines in text files. /etc/passwd has the account data (readable by all); /etc/shadow has the password hashes and password ages (only root).
lisa:x:1001:1001:Lisa Hassan:/home/lisa:/bin/bash| Field | Meaning |
|---|---|
1 lisa | User name |
2 x | The password is in /etc/shadow |
3 1001 | UID |
4 1001 | GID of the primary group |
5 Lisa Hassan | Comment (GECOS): full name |
6 /home/lisa | Home folder |
7 /bin/bash | Login shell |
lisa:$6$aBc…:20385:0:90:7:::Fields of shadow: user, password hash (! or !! = locked or no password), last change (days since 1970), min days, max days, warning days, inactive days, expire date.
Create users
useradd makes the account; passwd sets the password. The new home folder gets a copy of /etc/skel.
- Create a user with a full name.
useradd -c "Lisa Hassan" lisa - Set the password.
passwd lisa - Create a user with more settings in one go.
useradd -u 1500 -G wheel,webadmins -s /bin/bash -c "Omar Ali" omar - Create an account for a service that nobody logs in to.
useradd -r -s /sbin/nologin -d /var/lib/myapp myapp
| Option | Meaning |
|---|---|
-c | Comment (full name) |
-u | A chosen UID |
-g / -G | Primary group / extra groups |
-s | Login shell |
-d | Home folder |
-m / -M | Make / do not make the home folder |
-e | Expire date (YYYY-MM-DD) |
-r | System account (UID under 1000, no aging) |
Set the defaults for new users
useradd takes its defaults from /etc/login.defs and /etc/default/useradd. Change them once, and every new user gets them.
useradd -D
useradd -D -s /bin/bash
grep -E '^(UID_MIN|PASS_MAX_DAYS|PASS_MIN_DAYS|PASS_WARN_AGE|CREATE_HOME|HOME_MODE)' /etc/login.defs| File | Sets |
|---|---|
/etc/login.defs | UID/GID ranges, password aging defaults, create home, home permissions, umask |
/etc/default/useradd | Default shell, home base folder, skel folder, group, expire |
/etc/skel/ | Files every new home folder gets (like .bashrc) |
- Make every new user get a file with company rules.
echo "Read the IT policy: https://intranet.example.com/policy" > /etc/skel/README.txt - Make new passwords expire after 90 days by default.
sed -i 's/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 90/' /etc/login.defs
تذكّر
login.defs = numbers and rules, default/useradd = shell and home, skel = starter files. They only affect new users.
Change and delete users
usermod changes an existing account; userdel removes it.
usermod -aG webadmins lisa
usermod -s /sbin/nologin olduser
usermod -L lisa
usermod -U lisa
usermod -e 2026-12-31 contractor1
usermod -l lisa.hassan lisa
userdel -r contractor1-aG GROUPadds an extra group. Without-a,-Greplaces all extra groups.-L/-Ulock / unlock the password.-l NEW OLDrenames the login (the home folder keeps its name unless you add-d NEWHOME -m).userdel -ralso removes the home folder and the mail spool.
انتبه
usermod -G wheel lisa (without -a) removes lisa from every other extra group. Always use -aG to add.
في العمل
When someone leaves, first lock the account (usermod -L, chage -E 0), keep the files for a while, then delete. Find their files with find / -user NAME.
Set password aging
Password aging forces users to change passwords and can expire accounts. chage sets it per user; passwd has some short forms.
chage -l lisa
chage -M 90 -m 1 -W 7 lisa
chage -E 2026-12-31 contractor1
chage -d 0 lisa
passwd -e lisa| Option | Meaning |
|---|---|
-M 90 | Maximum: change the password every 90 days |
-m 1 | Minimum: wait 1 day before the next change |
-W 7 | Warn 7 days before it expires |
-I 14 | Lock the account 14 days after the password expired |
-E DATE | The whole account expires on this date (-E -1 = never) |
-d 0 | Force a new password at the next login |
نصيحة للامتحان
Tasks like "user X must change the password every 30 days" or "the account expires on …" use chage. For all new users, set PASS_MAX_DAYS in /etc/login.defs.
Give users a working environment
A new home folder starts as a copy of /etc/skel. The shell reads the profile files at login, so users get the same start settings.
- Put files for all new users in
/etc/skel(like.bashrcwith company aliases). - Settings for all users at every login: a file in
/etc/profile.d/. - Accounts that must not log in get the shell
/sbin/nologin.
Understand groups
A group gives the same rights to many users. Every user has one primary group and can be in many secondary (extra) groups.
- The primary group is the group of new files a user makes. On RHEL each user gets a private group with the same name.
- Secondary groups give access to shared files and folders.
- Groups are in
/etc/group(name, password placeholder, GID, members) and/etc/gshadow.
id lisa
uid=1001(lisa) gid=1001(lisa) groups=1001(lisa),1100(webadmins)
groups lisa
getent group webadmins
webadmins:x:1100:lisa,omarانتبه
A new group membership is active only after the user logs in again (or runs newgrp GROUP).
Create and change groups
groupadd makes a group, groupmod changes it, groupdel removes it. Add members with usermod -aG or gpasswd -a.
groupadd webadmins
groupadd -g 2000 dbadmins
groupmod -n web-admins webadmins
gpasswd -a lisa web-admins
gpasswd -d lisa web-admins
groupdel dbadminsTo edit the files by hand safely, use vigr (for /etc/group) and vipw (for /etc/passwd). They lock the files while you edit.
تذكّر
add member = usermod -aG GROUP USER or gpasswd -a USER GROUP. Remove member = gpasswd -d USER GROUP.
Remember the main points
The most important facts of this chapter, in short.
- root (UID 0) can do everything; system accounts run services; normal users start at UID 1000.
- Use sudo for admin work: members of the
wheelgroup may run all commands; own rules go in/etc/sudoers.d/withvisudo. - User data is in
/etc/passwd, passwords and aging in/etc/shadow, groups in/etc/group. useradd,usermod,userdelmanage users; defaults come from/etc/login.defsand/etc/default/useradd; new home folders get the files of/etc/skel.passwdsets a password;chagesets password aging (-Mmax days,-mmin days,-Wwarn,-Eexpire date).- Every user has one primary group and can have secondary groups (
usermod -aG group user). groupadd,groupmod,groupdelandgpasswdmanage groups.
Learn the key terms
The words of this chapter in simple English.
| Term | Meaning |
|---|---|
| UID / GID | The number of a user / a group. |
| root | The super user with UID 0. |
| System account | An account for a service, not for a person (UID below 1000). |
| sudo | Run one command as root (or another user), with rules in /etc/sudoers. |
| wheel | The group whose members may use sudo on RHEL. |
| PolicyKit (polkit) | Rules that let normal users do some admin actions in graphical tools. |
| /etc/shadow | The file with the password hashes and aging data. |
| Password aging | Rules for how long a password is valid. |
| Primary group | The group a new file of the user gets. |
| Secondary group | An extra group membership for more access. |
| /etc/skel | Files copied into every new home folder. |
Check what you learned
Think about the answer first, then open it.
1How do you create user lisa with a home folder and the shell /bin/bash?
useradd -s /bin/bash lisa (RHEL makes the home folder by default; -m makes sure).
2How do you add user lisa to the group sales without removing her other groups?
3How do you force lisa to change her password every 90 days?
4How do you give group helpdesk the right to restart sshd as root and nothing else?
visudo -f /etc/sudoers.d/helpdesk with the line %helpdesk ALL=(root) /usr/bin/systemctl restart sshd.
5Where do you put a file that every new user must get in the home folder?
In /etc/skel.
6Which file has the password hashes?
/etc/shadow (only root can read it).