Product SiteDocumentation Site

8.4. Benutzer- und Gruppendatenbanken

Die Liste der Benutzer ist normalerweise in der Datei /etc/passwd gespeichert, während die Datei /etc/shadow gehashte Passwörter speichert. Beide sind Textdateien in einem recht einfachen Format, das mit einem Texteditor gelesen und geändert werden kann. Jeder Benutzer ist darin in einer Zeile mit mehreren durch einen Doppelpunkt („:“) getrennten Feldern aufgeführt.

8.4.1. Benutzerliste: /etc/passwd

Hier ist die Liste der Felder in der Datei /etc/passwd:
  • login, zum Beispiel rhertzog;
  • password: this is a password encrypted by a one-way function (crypt), relying on DES, MD5, SHA-256 or SHA-512. The special value “x” indicates that the encrypted password is stored in /etc/shadow;
  • uid: eine eindeutige Zahl zur Identifizierung jeden Benutzers;
  • gid: eine eindeutige Zahl für die Hauptgruppe des Benutzers (Debian erstellt standardmäßig für jeden Benutzer eine besondere Gruppe);
  • GECOS: Datenfeld, das gewöhnlich den vollständigen Namen des Benutzers enthält;
  • Benutzerverzeichnis, das dem Benutzer zur Speicherung seiner persönlichen Dateien zugewiesen ist (die Umgebungsvariable $HOME verweist üblicherweise hierauf);
  • bei der Anmeldung auszuführendes Programm. Dies ist gewöhnlich ein Befehlszeileninterpreter (Shell), der dem Benutzer freie Hand lässt. Falls Sie hier /bin/false angeben (das nichts tut und die Steuerung gleich wieder zurück gibt), kann sich der Benutzer nicht anmelden.
As mentioned before, one can edit this file directly. But there are more elegant ways to apply changes, which are described in Abschnitt 8.4.3, „Ein bestehende Konto oder Passwort ändern“.

8.4.2. Die versteckte und verschlüsselte Passwortdatei: /etc/shadow

Die Datei /etc/shadow enthält die folgenden Felder:
  • Anmeldung;
  • verschlüsseltes Passwort;
  • mehrere Felder zur Verwaltung des Verfalls der Passwörter.
One can expire passwords using this file or set the time until the account is disabled after the password has expired.

8.4.3. Ein bestehende Konto oder Passwort ändern

The following commands allow modification of the information stored in specific fields of the user databases: passwd permits a regular user to change their password, which in turn, updates the /etc/shadow file (chpasswd allows administrators to update passwords for a list of users in batch mode); chfn (CHange Full Name), reserved for the super-user (root), modifies the GECOS field. chsh (CHange SHell) allows the user to change their login shell; however, available choices will be limited to those listed in /etc/shells; the administrator, on the other hand, is not bound by this restriction and can set the shell to any program of their choosing.
Schließlich ermöglicht der Befehl chage (CHange AGE) es dem Administrator, die Passwort-Verfallseinstellungen zu ändern (mit der Option -l Benutzer werden die aktuellen Einstellungen aufgelistet). Man kann auch den Verfall eines Passworts mit dem Befehl passwd -e Benutzer erzwingen, wodurch der Benutzer bei der nächsten Anmeldung sein Passwort ändern muss.
Besides these tools the usermod command allows to modify all the details mentioned above.

8.4.4. Ein Konto sperren

You may find yourself needing to “disable an account” (lock out a user), as a disciplinary measure, for the purposes of an investigation, or simply in the event of a prolonged or definitive absence of a user. A disabled account means the user cannot login or gain access to the machine. The account remains intact on the machine and no files or data are deleted; it is simply inaccessible. This is accomplished by using the command passwd -l user (lock). Re-enabling the account is done in similar fashion, with the -u option (unlock). This, however, only prevents password-based logins by the user. The user might still be able to access the system using an SSH key (if configured). To prevent even this possibility you have to expire the account as well using either chage -E 1user or usermod -e 1 user (giving a value of -1 in either of these commands will reset the expiration date to never). To (temporarily) disable all user accounts just create the file /etc/nologin.
You can disable a user account not only by locking it as described above, but also by changing its default login shell (chsh -s shell user). With the latter changed to /usr/sbin/nologin, a user gets a polite message informing that a login is not possible, while /bin/false just exits while returning false. There is no switch to restore the previous shell. You have to get and keep that information before you change the setting. These shells are often used for system users which do not require any login availability.

8.4.5. Gruppenliste: /etc/group

Gruppen sind in der Datei /etc/group aufgelistet, einer einfachen Textdatenbank in einem der Datei /etc/passwd ähnlichen Format mit folgenden Feldern:
  • Gruppenname;
  • Passwort (optional): Dies wird nur dann zum Beitritt zu einer Gruppe benutzt, wenn jemand dort normalerweise nicht Mitglied ist (mit den Befehlen newgrp oder sg, siehe Seitenleiste ZURÜCK ZU DEN GRUNDLAGEN Mit mehreren Gruppen arbeiten);
  • gid: eindeutige Gruppenidentifikationsnummer;
  • Mitgliederliste: Liste mit den Namen der Benutzer, die Mitglieder der Gruppe sind, getrennt durch Kommata.
Die Befehle groupadd und groupdel fügen eine Gruppe hinzu beziehungsweise löschen sie. Der Befehl groupmod ändert die Informationen über eine Gruppe (sein gid, das heißt seine Kennung). Der Befehl gpasswd Gruppe ändert das Passwort der Gruppe, während der Befehl gpasswd -r Gruppe es löscht.