Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

groupadd

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

Niveau
RHCSA-examen
Groep
Gebruikers en groepen
Root nodig
Ja
Pakket
shadow-utils
Ook
groupmod, groupdel

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

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.

Zo schrijf je het

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

Opties 17

Meest gebruikt

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.

Voorbeelden 11

$ als gewone gebruiker# als root (of met 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.

Let op

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

Bestanden

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

Exitcodes

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.