Product SiteDocumentation Site

8.4. Bases de dades d'usuaris i de grups

La llista d'usuaris s'emmagatzema normalment al fitxer /etc/passwd, mentre que el fitxer /etc/shadow emmagatzema les contrasenyes xifrades («hashed»). Tots dos són fitxers de text, en un format relativament senzill, que es poden llegir i modificar amb un editor de text. Cada usuari apareix en una línia amb diversos camps separats per dos punts (“:”).

8.4.1. Llista d'usuaris: /etc/passwd

Aquesta és la llista de camps del fitxer /etc/passwd:
  • nom d'usuari, per exemple 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: número únic que identifica cada usuari;
  • gid: número únic per al grup principal de l'usuari (Debian crea per defecte un grup específic per a cada usuari);
  • GECOS: camp de dades que normalment conté el nom complet de l'usuari;
  • directori d'inici de sessió, assignat a l'usuari per a l'emmagatzematge dels seus fitxers personals (la variable d'entorn $HOME generalment apunta aquí);
  • programa a executar en iniciar la sessió. Normalment es tracta d'un intèrpret d'ordres («shell»), que dóna llibertat a l'usuari. Si especifiqueu /bin/false (que no fa res i retorna el control immediatament), l'usuari no podrà iniciar la sessió.
As mentioned before, one can edit this file directly. But there are more elegant ways to apply changes, which are described in Secció 8.4.3, «Modificar un compte o contrasenya ja existents».

8.4.2. El fitxer de les contrasenyes ocultes i encriptades: /etc/shadow

El fitxer /etc/shadow conté els següents camps:
  • usuari;
  • contrasenya encriptada;
  • diversos camps que gestionen el venciment de la contrasenya.
One can expire passwords using this file or set the time until the account is disabled after the password has expired.

8.4.3. Modificar un compte o contrasenya ja existents

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.
Finalment, l'ordre chage (de l'anglès «CHange AGE») permet a l'administrador canviar la configuració del venciment de la contrasenya (l'opció -l usuari llistarà la configuració actual). També podeu forçar l'expiració d'una contrasenya utilitzant l'ordre passwd -e usuari, que requerirà que l'usuari canviï la seva contrasenya la pròxima vegada que iniciï sessió.
Besides these tools the usermod command allows to modify all the details mentioned above.

8.4.4. Desactivar un compte

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. Llista de grups: /etc/group

Els grups estan llistats al fitxer /etc/group, una simple base de dades en text pla en un format similar al del fitxer /etc/passwd, amb els següents camps:
  • nom del grup;
  • contrasenya (opcional): només s'utilitza per unir-se a un grup quan un no és un membre habitual (amb les ordres newgrp o sg, vegeu la barra lateral TORNAR A LES BASES Treballar amb diversos grups);
  • gid: número únic d'identificació de grup;
  • llista de membres: llista de noms d'usuaris que són membres del grup, separats per comes.
Les ordres addgroup i delgroup afegeixen o suprimeixen un grup, respectivament. L'ordre groupmod modifica la informació d'un grup (el seu gid o identificador). L'ordre gpasswd grup canvia la contrasenya del grup, mentre que l'ordre gpasswd -rgrup el suprimeix.