Gibt es in Linux eine Möglichkeit, die Benutzer- / Gruppeneigenschaften zu aktualisieren, ohne sich erneut anmelden zu müssen?

10770
wonea

Nach dem Bearbeiten von / etc / group und dem Hinzufügen eines Benutzers zu Gruppen, zu denen er nicht gehört, kann der Benutzer die neu erworbenen Berechtigungen erst dann verwenden, wenn er eine neue Sitzung startet.

Gibt es einen Befehl zum Aktualisieren von Benutzer- / Gruppeneigenschaften in einer laufenden Sitzung?

22
Gibt es einen Grund, warum Sie die Datei von Hand bearbeiten, anstatt `useradd -G groupname username` zu ​​verwenden? Bobby vor 13 Jahren 1
@ Bobby: das würde keinen Unterschied machen. niXar vor 13 Jahren 3
Sie könnten [diese Antwort] suchen (https://superuser.com/a/354475/500826). Pablo Bianchi vor 6 Jahren 0

2 Antworten auf die Frage

14
niXar

At the kernel level, group membership is a property of each process. Unless it has the appropriate capability (CAP_SETGID if I'm not mistaken), i.e. root privileges for all intents and purposes, a process cannot belong to a new group.

A user does not exist as an object at the kernel level; only processes (and files) do. A process has a uid (effective and whatnot) and a list of group ids.

When you are adding a user to a group, the kernel has no idea what it means. It only knows, indirectly, that the next time /bin/login or /usr/bin/newgrp is run a process with that user id will have a new group id in its list.

So, to answer your question, if you're speaking of a Gnome or KDE session, you have to restart it indeed. Or if you only care about the result of one command as far as that new group is concerned, you can use newgrp I just mentioned. It will start a new shell with the newly added group.

5
Andy Shellam

Ich habe bereits gelesen, dass der Befehl newgrp dies tut, jedoch nur für die aktuelle Shell. Es scheint keine bessere Alternative zu sein, als sich aus- und wieder einzuloggen.

Was newgrp macht, ist eigentlich eine neue Shell zu starten. Wenn du also davon kommst, bist du wieder in deiner alten Schale. Normalerweise mache ich einfach 'exec newgrp' niXar vor 13 Jahren 3