الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

الفصل 10الاسم في الدورة: Managing Local Users and Groups

Manage local users and groups

Every process and every file belongs to a user and a group. As an admin you create accounts for people and services, put them in groups, give some of them admin rights with sudo, and set password rules. This chapter shows all of it.

  • 7 الدروس
  • 21 الأوامر
  • 2 المعامل

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

المهارات في هذا الفصل

  • إنشاء المستخدمين والمجموعات واستخدام sudo وضبط قواعد كلمات المرور

10.1

Know the kinds of users

Linux knows users by a number, the UID. The number decides the kind of user.

KindUIDExampleUsed for
Superuser0rootFull control over the system
System users1 – 999apache, sshd, chronyRun services with few rights
Normal users1000 and upanna, studentPeople
id
uid=1000(student) gid=1000(student) groups=1000(student),10(wheel)
id apache
uid=48(apache) gid=48(apache) groups=48(apache)
ps -o user,pid,cmd -C sshd

تذكّر

Services run as their own system user. If somebody breaks into the web server, he only gets the rights of apache, not of root.

الأوامر في هذا الدرس

10.2

Read the user database files

Local accounts live in four text files in /etc.

FileWhat is in itWho can read it
/etc/passwdUsers: name, UID, GID, comment, home, shellEverybody
/etc/shadowPassword hashes and password-age rulesOnly root
/etc/groupGroups and their membersEverybody
/etc/gshadowGroup passwords and group adminsOnly root
grep anna /etc/passwd
anna:x:1001:1001:Anna Admin:/home/anna:/bin/bash
grep anna /etc/shadow
anna:$y$j9T$Hd3...$Qx1...:20753:0:90:7:::
grep wheel /etc/group
wheel:x:10:student,anna
getent passwd anna

The 7 fields of /etc/passwd: name : x : UID : GID : comment : home : shell. The x means "the password is in /etc/shadow".

انتبه

Do not edit these files with a normal editor while users log in. Use the tools (useradd, usermod …) or vipw / vigr, which lock the file.

10.3

Become root with su and sudo

Work as a normal user. Get root rights only for the commands that need them: with sudo (one command) or su - (a root shell).

sudo dnf install -y tmux
[sudo] password for student:
sudo -i
whoami
root
exit
su -
Password:
exit
su - anna
sudo -l
CommandAsks forResult
sudo CMDYour passwordRuns one command as root, logged in /var/log/secure
sudo -iYour passwordA root login shell
su -The root passwordA root login shell
su - annaanna's password (nothing if you are root)A login shell as anna
sudo -lYour passwordShows what you may run with sudo

تذكّر

su - with the dash loads the full environment of the new user (PATH, home folder). Without the dash you keep your old environment — a common source of "command not found".

في العمل

Many companies lock the root password (passwd -l root) and let admins work only with sudo. Every action then has a name in the log.

10.4

Give admin rights with sudo

Members of the group wheel may run every command with sudo. For smaller rights, write a rule in /etc/sudoers.d/.

usermod -aG wheel anna
visudo -f /etc/sudoers.d/webteam
visudo -c
/etc/sudoers: parsed OK
/etc/sudoers.d/webteam: parsed OK
/etc/sudoers.d/webteam
# The web team may manage Apache, nothing else
%webteam  ALL=(root)  /usr/bin/systemctl restart httpd, /usr/bin/systemctl status httpd
# Backup user, no password (for scripts)
backup    ALL=(root)  NOPASSWD: /usr/bin/rsync

The format: who where=(as whom) which commands. % before a name means a group.

انتبه

Always use visudo. It checks the syntax before it saves. One wrong character in a sudoers file can lock everybody out of sudo. More: Give limited admin rights with sudo.

10.5

Create, change and delete users

useradd creates, usermod changes and userdel deletes a user. passwd sets the password.

useradd anna
passwd anna
useradd -c "Omar Ali" -G wheel,webteam -s /bin/bash omar
useradd -u 2001 -d /srv/app -s /sbin/nologin appuser
usermod -c "Anna Admin" anna
usermod -aG webteam anna
usermod -L omar
usermod -U omar
userdel -r olduser
OptionMeaning
-c "text"Comment (often the full name)
-G g1,g2Extra (supplementary) groups
-aG g (usermod)Add a group and keep the old ones
-u UID / -g GROUPChoose the UID / the primary group
-d DIR / -mHome folder / create it
-s SHELLLogin shell (/sbin/nologin = no login)
-L / -ULock / unlock the password
userdel -rAlso delete the home folder and the mail spool

انتبه

usermod -G webteam anna without -a removes anna from all her other extra groups. Always use -aG to add.

Defaults for new users come from /etc/login.defs and /etc/default/useradd. Files in /etc/skel are copied into every new home folder. Details: Set defaults for new users.

10.6

Manage groups

Groups give rights to many users at once. A user has one primary group (owner group of new files) and can be in many supplementary groups.

groupadd webteam
groupadd -g 3000 finance
groupmod -n web webteam
gpasswd -a anna web
gpasswd -d anna web
groupdel finance
groups anna
anna : anna wheel web
newgrp web

ملاحظة

A new group membership works only after the user logs in again (or runs newgrp GROUP in the shell).

10.7

Set password rules

Use chage to force password changes and to lock old accounts. Use /etc/security/pwquality.conf for the length and the strength.

chage -l anna
Last password change                    : Oct 27, 2026
Password expires                        : Jan 25, 2027
Minimum number of days between password change : 0
Maximum number of days between password change : 90
Number of days of warning before password expires : 7
chage -M 90 -m 1 -W 7 anna
chage -d 0 anna
chage -E 2026-12-31 contractor
passwd -e omar
OptionMeaning
-M 90The password must change every 90 days
-m 1Wait at least 1 day before the next change
-W 7Warn 7 days before it expires
-I 14Lock the account 14 days after the password expired
-d 0Force a new password at the next login
-E DATEThe whole account expires on that date
/etc/security/pwquality.conf
minlen = 12
minclass = 3
dictcheck = 1

نصيحة للامتحان

For all new users, change PASS_MAX_DAYS in /etc/login.defs. chage changes only users who already exist. More: Set password aging.

تدرّب

كل الأوامر في هذا الفصل