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

groupadd

Create a group (groupadd), change it (groupmod) or delete it (groupdel).

المستوى
امتحان RHCSA
المجموعة
المستخدمون والمجموعات
يحتاج root
نعم
الحزمة
shadow-utils
يُسمّى أيضًا
groupmod, groupdel

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

ماذا يفعل

Groups give the same rights to many users, for example write access to a shared folder. The groups are in /etc/group and /etc/gshadow. The GID comes from the range in /etc/login.defs (GID_MIN … GID_MAX) unless you give one.

groupmod renames a group or changes its GID. groupdel removes a group, but not if it is the primary group of a user.

Add members with usermod -aG GROUP USER or gpasswd -a USER GROUP.

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

groupadd [OPTION]... GROUP
groupmod [OPTION]... GROUP
groupdel [OPTION]... GROUP

الخيارات 17

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

groupadd

-g, --gid GID
Use this GID.
-r, --system
Create a system group (GID under 1000).
-f, --force
Exit with success if the group already exists (and pick another GID if -g is used).
-o, --non-unique
Allow a GID that is used already (with -g).
-U, --users USER1[,USER2...]
Add these users as members right away.
-K, --key KEY=VALUE
Override a value of /etc/login.defs (like GID_MIN).
-p, --password HASH
Set a hashed group password (not recommended).
-R, --root DIR
Work in this chroot folder.
-P, --prefix DIR
Use the files under this prefix folder.
-h, --help
Show help.

groupmod

-n, --new-name NEW_GROUP
Rename the group.
-g, --gid GID
Change the GID (files keep the old number; fix them with find).
-a, --append
With -U: add the users to the members (do not replace).
-U, --users USER1[,USER2...]
Set the member list.
-o, --non-unique
Allow a GID that is used already.
-p, --password HASH
Change the hashed group password.

groupdel

-f, --force
Delete the group even if it is the primary group of a user.

أمثلة 11

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

  1. 1Create a group

    groupadd webadmins

    Gets the next free GID.

  2. 2Create a group with a fixed GID

    groupadd -g 3000 sales

    Same GID on all servers for NFS shares.

  3. 3Create a system group for a service

    groupadd -r appsvc

    GID under 1000.

  4. 4Create a group with members

    groupadd -U anna,bob projectx

    Newer versions only; else use gpasswd -a.

  5. 5Rename a group

    groupmod -n web-admins webadmins

    Members and files keep working: they use the GID.

  6. 6Change the GID and fix the files

    groupmod -g 3100 sales
    find / -xdev -gid 3000 -exec chgrp -h sales {} +

    Files still have the old number until you change them.

  7. 7Delete a group

    groupdel projectx

    Fails if it is the primary group of a user.

  8. 8Set up a shared team folder

    groupadd sales
    mkdir /srv/sales
    chgrp sales /srv/sales; chmod 2770 /srv/sales

    2 = setgid: new files get the group sales (see the permissions chapter).

  9. 9Do not fail when the group exists (scripts)

    groupadd -f sales

    Safe to run twice, for example in Ansible-like scripts.

  10. 10Check the group

    getent group sales
    sales:x:3000:anna,bob

    Name, password placeholder, GID, members.

  11. 11Find groups with no members (cleanup)

    awk -F: '$4 == "" && $3 >= 1000 {print $1}' /etc/group

    Private groups of users are listed too; they are normal.

انتبه

  • groupdel does not change files: they then show the old GID number.
  • A user gets new groups only after a new login.

الملفات

/etc/group, /etc/gshadow
The group data.
/etc/login.defs
GID_MIN, GID_MAX, SYS_GID_MIN, SYS_GID_MAX.

رموز الخروج

0Done.
2Wrong syntax.
3Wrong value for an option.
4The GID is used already.
6The group does not exist (groupmod, groupdel).
8Cannot delete the primary group of a user (groupdel).
9The group name is used already.
10Could not update the group file.