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

gpasswd

Add or remove members of a group, set group admins, or set a group password.

المستوى
امتحان RHCSA
المجموعة
المستخدمون والمجموعات
يحتاج root
للتغييرات
الحزمة
shadow-utils

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

ماذا يفعل

gpasswd changes /etc/group and /etc/gshadow. Its most useful jobs are -a (add a member) and -d (remove a member) — removing is not easy with usermod on older systems.

root can also make users group administrators (-A): they may then add and remove members of that group themselves, without sudo.

Group passwords (gpasswd GROUP) let non-members join with newgrp. They are rarely a good idea.

طريقة الكتابة

gpasswd [OPTION] GROUP

الخيارات 8

الأكثر استخدامًا

-a, --add USER
Add the user to the group.
-d, --delete USER
Remove the user from the group.
-M, --members USER, ...
Set the full member list (replaces it).
-A, --administrators USER, ...
Set the group administrators.
-r, --remove-password
Remove the group password (only members can use newgrp).
-R, --restrict
Lock the group: only members can use newgrp.
-Q, --root DIR
Work in this chroot folder.
-h, --help
Show help.

أمثلة 10

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

  1. 1Add a member

    gpasswd -a lisa webadmins
    Adding user lisa to group webadmins

    Same as usermod -aG webadmins lisa.

  2. 2Remove a member

    gpasswd -d lisa webadmins
    Removing user lisa from group webadmins

    The easy way to take a group away.

  3. 3Set the whole member list

    gpasswd -M anna,bob,carol sales

    Replaces all members; good for a sync from a list.

  4. 4Let a team lead manage the group

    gpasswd -A anna sales
    gpasswd -a dave sales

    anna (as group admin) adds members without sudo.

  5. 5Remove all members

    gpasswd -M '' sales

    An empty list.

  6. 6Remove the group password

    gpasswd -r sales

    Only members can then use newgrp sales.

  7. 7Check the members and admins

    getent group sales; getent gshadow sales
    sales:x:3000:anna,bob,carol
    sales:!::anna:anna,bob,carol

    gshadow field 3 = admins, field 4 = members.

  8. 8Remove a user from all extra groups (offboarding)

    for g in $(id -Gn olduser | cut -d' ' -f2-); do gpasswd -d olduser "$g"; done

    The first group is the primary group and stays.

  9. 9Take away admin rights

    gpasswd -d lisa wheel

    She keeps sudo until her session ends; check open sessions.

  10. 10Audit the members of admin groups

    for g in wheel webadmins; do getent group "$g"; done

    Review these lists often.

انتبه

  • -M replaces the list: users not in it are removed.
  • Membership changes work after the next login of the user.

الملفات

/etc/group
Group name, GID and members.
/etc/gshadow
Group password, admins and members.

رموز الخروج

0Done.
1Error (not allowed, user or group not found).

الدليل الكامل

هذه الصفحة تشرح الأمر بكلمات بسيطة. الدليل الأصلي فيه كل التفاصيل.

في الطرفية: man gpasswd