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

newgrp

Start a new shell with another primary group — useful right after you were added to a group.

Niveau
Dagelijks Linux
Groep
Gebruikers en groepen
Root nodig
Nee
Pakket
shadow-utils

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

Wat het doet

When an admin adds you to a group, your running sessions do not have it yet. newgrp GROUP starts a new shell in which GROUP is your primary group (new files get this group) and the group is active.

If you are not a member, newgrp asks for the group password (if one is set). exit returns to the old shell.

Zo schrijf je het

newgrp [-] [GROUP]

Opties 2

Meest gebruikt

GROUP
The group to use. Without a name: your primary group from the account.
-
Start like a new login (reset the environment).

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Use a new group without a new login

    newgrp webadmins
    id -gn
    webadmins

    exit to go back.

  2. 2Create files with a team group

    newgrp sales
    touch report.txt; ls -l report.txt
    -rw-r--r--. 1 anna sales 0 Oct 25 10:12 report.txt

    New files get the primary group sales.

  3. 3Check the active groups before and after

    id -Gn; newgrp webadmins; id -Gn

    The new shell has the group.

  4. 4Go back to the normal group

    exit

    Leaves the newgrp shell.

  5. 5Start as a new login

    newgrp - sales

    Clean environment, like a new login.

  6. 6Run one command with a group (sg)

    sg sales -c 'touch /srv/sales/plan.txt'

    sg = newgrp for one command.

  7. 7Join with a group password

    newgrp projectx
    Password:

    Works only if a group password was set (rare).

  8. 8In a script after adding a user to docker or podman groups

    newgrp libvirt

    For example after usermod -aG libvirt $USER to use virsh without a new login.

  9. 9Check the group of new files

    umask; newgrp sales; touch x; stat -c '%G' x
    sales

    Shows which group new files get.

  10. 10Best alternative: log in again

    exit

    A new login gives all groups at once, not only one.

Let op

  • newgrp starts a new shell; your old variables and history are not in it.
  • A setgid folder (chmod g+s) is often a better way to give files a team group.

Bestanden

/etc/group, /etc/gshadow
Members and group passwords.

Exitcodes

0Done (exit code of the shell).
1Not allowed or the group does not exist.

Volledige handleiding

Deze pagina legt het commando uit in eenvoudige woorden. De originele handleiding heeft elk detail.

In je terminal: man newgrp