Cap. 4. Autentificare și controale de acces

Cuprins

4.1. Autentificare normală Unix
4.2. Gestionarea informațiilor privind contul și parola
4.3. Parolă bună
4.4. Crearea unei parole criptate
4.5. PAM și NSS
4.5.1. Configuration files accessed by PAM and NSS
4.5.2. The modern centralized system management
4.5.3. "Why GNU su does not support the wheel group"
4.5.4. Stricter password rule
4.6. Security of authentication
4.6.1. Secure password on the Internet
4.6.2. Shell securizat
4.6.3. Extra security measures for the Internet
4.6.4. Securing the root password
4.7. Other access controls
4.7.1. Liste de control al accesului (ACL)
4.7.2. sudo
4.7.3. PolicyKit
4.7.4. Restricting access to some server services
4.7.5. Linux security features

Când o persoană (sau un program) solicită acces la sistem, autentificarea confirmă identitatea ca fiind una de încredere.

[Avertisment] Avertisment

Erorile de configurare ale PAM vă pot bloca accesul la propriul sistem. Trebuie să aveți la îndemână un CD de recuperare sau să configurați o partiție de pornire alternativă. Pentru a recupera sistemul, porniți-l cu ajutorul acestora și remediați problemele de acolo.

Autentificarea normală Unix este asigurată de modulul pam_unix(8) din cadrul PAM (Pluggable Authentication Modules). Cele trei fișiere de configurare importante, cu intrări separate prin „:”, sunt următoarele.


/etc/passwd” conține următoarele.

 ...
user1:x:1000:1000:User1 Name,,,:/home/user1:/bin/bash
user2:x:1001:1001:User2 Name,,,:/home/user2:/bin/bash
 ...

Așa cum se explică în passwd(5), fiecare intrare separată prin „:” din acest fișier înseamnă următoarele.

  • Nume de autentificare

  • Intrarea specificării parolei

  • ID-ul numeric al utilizatorului

  • ID-ul numeric al grupului

  • Nume utilizator sau câmp comentariu

  • Directorul personal al utilizatorului

  • Interpret opțional de comenzi pentru utilizator

A doua intrare din „/etc/passwd” a fost utilizată pentru introducerea parolei criptate. După introducerea „/etc/shadow”, această intrare este utilizată pentru introducerea specificațiilor parolei.


Fișierul „/etc/shadow” conține următoarele câmpuri.

 ...
user1:$1$Xop0FYH9$IfxyQwBe9b8tiyIkt2P4F/:13262:0:99999:7:::
user2:$1$vXGZLVbS$ElyErNf/agUDsm1DehJMS/:13261:0:99999:7:::
 ...

După cum se explică în shadow(5), fiecare intrare separată prin „:” din acest fișier înseamnă următoarele.

  • Nume de autentificare

  • Parolă criptată (inițialele „$1$” indică utilizarea criptării MD5. Simbolul „*” indică faptul că nu există date de conectare.)

  • Data ultimei modificări a parolei, exprimată ca număr de zile de la 1 ianuarie 1970

  • Numărul de zile pe care utilizatorul va trebui să le aștepte înainte de a i se permite să își schimbe din nou parola

  • Numărul de zile după care utilizatorul va trebui să își schimbe parola

  • Numărul de zile înainte de expirarea parolei în care utilizatorul trebuie avertizat

  • Numărul de zile după expirarea parolei în care parola ar trebui să fie încă acceptată

  • Data expirării contului, exprimată ca număr de zile de la 1 ianuarie 1970

Fișierul „/etc/group” conține următoarele câmpuri.

group1:x:20:user1,user2

După cum se explică în group(5), fiecare intrare separată prin „:” din acest fișier are următoarea semnificație.

  • Numele grupului

  • Parolă criptată (nu este utilizată efectiv)

  • ID-ul numeric al grupului

  • Listă separată prin virgule a numelor de utilizatori

[Notă] Notă

/etc/gshadow” oferă o funcție similară cu „/etc/shadow” pentru „/etc/group”, dar nu este utilizat în mod real.

[Notă] Notă

Apartenența efectivă a unui utilizator la un grup poate fi adăugată dinamic dacă se adaugă linia „auth optional pam_group.so” în „/etc/pam.d/common-auth” și se definește în „/etc/security/group.conf”. Consultați pam_group(8).

[Notă] Notă

Pachetul base-passwd conține o listă oficială a utilizatorilor și grupurilor: „/usr/share/doc/base-passwd/users-and-groups.html”.

Iată câteva comenzi importante pentru gestionarea informațiilor contului.


Este posibil să aveți nevoie de privilegii de root pentru ca unele funcții să funcționeze. Consultați crypt(3) pentru criptarea parolelor și a datelor.

[Notă] Notă

În sistemul configurat cu PAM și NSS ca mașină Debian salsa, conținutul local „/etc/passwd”, „/etc/group” și „/etc/shadow” poate să nu fie utilizat în mod activ de sistem. Comenzile de mai sus sunt valabile chiar și în astfel de medii.

Când creați un cont în timpul instalării sistemului sau cu comanda passwd(1), ar trebui să alegeți o parolă bună care să conțină cel puțin 6-8 caractere, inclusiv unul sau mai multe caractere din fiecare dintre următoarele seturi, conform passwd(1).

  • literele alfabetului în minusculă

  • cifrele de la 0 la 9

  • Semne de punctuație

[Avertisment] Avertisment

Nu alegeți cuvinte ușor de ghicit pentru parolă. Numele contului, numărul de asigurare socială, numărul de telefon, adresa, data nașterii, numele membrilor familiei sau al animalelor de companie, cuvinte din dicționar, secvențe simple de caractere precum „12345” sau „qwerty” etc. sunt toate alegeri nepotrivite pentru parolă.

Există instrumente independente pentru a genera parole criptate cu „salt” (sare).


Modern Unix-like systems such as the Debian system provide PAM (Pluggable Authentication Modules) and NSS (Name Service Switch) mechanism to the local system administrator to configure his system. The role of these can be summarizes as the following.

  • PAM offers a flexible authentication mechanism used by the application software thus involves password data exchange.

  • NSS offers a flexible name service mechanism which is frequently used by the C standard library to obtain the user and group name for programs such as ls(1) and id(1).

These PAM and NSS systems need to be configured consistently.

The notable packages of PAM and NSS systems are the following.


  • "The Linux-PAM System Administrators' Guide" in libpam-doc is essential for learning PAM configuration.

  • "System Databases and Name Service Switch" section in glibc-doc-reference is essential for learning NSS configuration.

[Notă] Notă

You can see more extensive and current list by "aptitude search 'libpam-|libnss-'" command. The acronym NSS may also mean "Network Security Service" which is different from "Name Service Switch".

[Notă] Notă

PAM is the most basic way to initialize environment variables for each program with the system wide default value.

Under systemd, libpam-systemd package is installed to manage user logins by registering user sessions in the systemd control group hierarchy for logind. See systemd-logind(8), logind.conf(5), and pam_systemd(8).

Here are a few notable configuration files accessed by PAM and NSS.


The limitation of the password selection is implemented by the PAM modules, pam_unix(8) and pam_cracklib(8). They can be configured by their arguments.

[Indicație] Indicație

PAM modules use suffix ".so" for their filenames.

The modern centralized system management can be deployed using the centralized Lightweight Directory Access Protocol (LDAP) server to administer many Unix-like and non-Unix-like systems on the network. The open source implementation of the Lightweight Directory Access Protocol is OpenLDAP Software.

The LDAP server provides the account information through the use of PAM and NSS with libpam-ldapd and libnss-ldapd packages for the Debian system. Several actions are required to enable this (I have not used this setup and the following is purely secondary information. Please read this in this context.).

  • You set up a centralized LDAP server by running a program such as the stand-alone LDAP daemon, slapd(8).

  • You change the PAM configuration files in the "/etc/pam.d/" directory to use "pam_ldap.so" instead of the default "pam_unix.so".

  • You change the NSS configuration in the "/etc/nsswitch.conf" file to use "ldap" instead of the default ("compat" or "file").

  • You must make libpam-ldapd to use SSL (or TLS) connection for the security of password.

  • You may make libnss-ldapd to use SSL (or TLS) connection to ensure integrity of data at the cost of the LDAP network overhead.

  • You should run nscd(8) locally to cache any LDAP search results in order to reduce the LDAP network traffic.

See documentations in nsswitch.conf(5), pam.conf(5), ldap.conf(5), and "/usr/share/doc/libpam-doc/html/" offered by the libpam-doc package and "info libc 'Name Service Switch'" offered by the glibc-doc package.

Similarly, you can set up alternative centralized systems with other methods.

[Notă] Notă

The information here may not be sufficient for your security needs but it should be a good start.

The Secure Shell (SSH) program provides secure encrypted communications between two untrusted hosts over an insecure network with the secure authentication. It consists of the OpenSSH client, ssh(1), and the OpenSSH daemon, sshd(8). This SSH can be used to tunnel an insecure protocol communication such as POP and X securely over the Internet with the port forwarding feature.

The client tries to authenticate itself using host-based authentication, public key authentication, challenge-response authentication, or password authentication. The use of public key authentication enables the remote password-less login. See Secțiune 6.3, „The remote access server and utilities (SSH)”.

To prevent people to access your machine with root privilege, you need to make following actions.

  • Prevent physical access to the hard disk

  • Lock UEFI/BIOS and prevent booting from the removable media

  • Set password for GRUB interactive session

  • Lock GRUB menu from editing

With physical access to hard disk, resetting the password is relatively easy with following steps.

  1. Move the hard disk to a PC with CD bootable UEFI/BIOS.

  2. Boot system with a rescue media (Debian boot disk, Knoppix CD, GRUB CD, …).

  3. Mount root partition with read/write access.

  4. Edit "/etc/passwd" in the root partition and make the second entry for the root account empty.

If you have edit access to the GRUB menu entry (see Secțiune 3.1.2, „Etapa 2: încărcătorul de pornire”) for grub-rescue-pc at boot time, it is even easier with following steps.

  1. Boot system with the kernel parameter changed to something like "root=/dev/hda6 rw init=/bin/sh".

  2. Edit "/etc/passwd" and make the second entry for the root account empty.

  3. Reboot system.

The root shell of the system is now accessible without password.

[Notă] Notă

Once one has root shell access, he can access everything on the system and reset any passwords on the system. Further more, he may compromise password for all user accounts using brute force password cracking tools such as john and crack packages (see Secțiune 9.5.11, „System security and integrity check”). This cracked password may lead to compromise other systems.

The only reasonable software solution to avoid all these concerns is to use software encrypted root partition (or "/etc" partition) using dm-crypt and initramfs (see Secțiune 9.9, „Data encryption tips”). You always need password to boot the system, though.

There are access controls to the system other than the password based authentication and file permissions.

[Notă] Notă

See Secțiune 9.4.16, „Alt-SysRq key” for restricting the kernel secure attention key (SAK) feature.

ACLs are a superset of the regular permissions as explained in Secțiune 1.2.3, „Permisiuni ale sistemului de fișiere”.

You encounter ACLs in action on modern desktop environment. When a formatted USB storage device is auto mounted as, e.g., "/media/penguin/USBSTICK", a normal user penguin can execute:

 $ cd /media/penguin
 $ ls -la
total 16
drwxr-x---+ 1 root    root    16 Jan 17 22:55 .
drwxr-xr-x  1 root    root    28 Sep 17 19:03 ..
drwxr-xr-x  1 penguin penguin 18 Jan  6 07:05 USBSTICK

"+" in the 11th column indicates ACLs are in action. Without ACLs, a normal user penguin shouldn't be able to list like this since penguin isn't in root group. You can see ACLs as:

 $ getfacl .
# file: .
# owner: root
# group: root
user::rwx
user:penguin:r-x
group::---
mask::r-x
other::---

Here:

  • "user::rwx", "group::---", and "other::---" correspond to the regular owner, group, and other permissions.

  • The ACL "user:penguin:r-x" allows a normal user penguin to have "r-x" permissions. This enabled "ls -la" to list directory content.

  • The ACL "mask::r-x" sets the upper bound of permissions.

See "POSIX Access Control Lists on Linux", acl(5), getfacl(1), and setfacl(1) for more.

sudo(8) is a program designed to allow a sysadmin to give limited root privileges to users and log root activity. sudo requires only an ordinary user's password. Install sudo package and activate it by setting options in "/etc/sudoers". See configuration example at "/usr/share/doc/sudo/examples/sudoers" and Secțiune 1.1.12, „Configurarea «sudo»”.

My usage of sudo for the single user system (see Secțiune 1.1.12, „Configurarea «sudo»”) is aimed to protect myself from my own stupidity. Personally, I consider using sudo a better alternative than using the system from the root account all the time. For example, the following changes the owner of "some_file" to "my_name".

$ sudo chown my_name some_file

Of course if you know the root password (as self-installed Debian users do), any command can be run under root from any user's account using "su -c".

PolicyKit is an operating system component for controlling system-wide privileges in Unix-like operating systems.

Newer GUI applications are not designed to run as privileged processes. They talk to privileged processes via PolicyKit to perform administrative operations.

PolicyKit limits such operations to user accounts belonging to the sudo group on the Debian system.

A se vedea polkit(8).

For system security, it is a good idea to disable as much server programs as possible. This becomes critical for network servers. Having unused servers, activated either directly as daemon or via super-server program, are considered security risks.

Many programs, such as sshd(8), use PAM based access control. There are many ways to restrict access to some server services.

See Secțiune 3.5, „Gestionarea sistemului”, Secțiune 4.5.1, „Configuration files accessed by PAM and NSS”, and Secțiune 5.7, „Infrastructura netfilter”.

[Indicație] Indicație

Sun RPC services need to be active for NFS and other RPC based programs.

[Indicație] Indicație

If you have problems with remote access in a recent Debian system, comment out offending configuration such as "ALL: PARANOID" in "/etc/hosts.deny" if it exists. (But you must be careful on security risks involved with this kind of action.)

Linux kernel has evolved and supports security features not found in traditional UNIX implementations.

Linux supports extended attributes which extend the traditional UNIX attributes (see xattr(7)).

Linux divides the privileges traditionally associated with superuser into distinct units, known as capabilities(7), which can be independently enabled and disabled. Capabilities are a per-thread attribute since kernel version 2.2.

The Linux Security Module (LSM) framework provides a mechanism for various security checks to be hooked by new kernel extensions. For example:

Since these extensions may tighten privilege model tighter than the ordinary Unix-like security model policies, even the root power may be restricted. You are advised to read the Linux Security Module (LSM) framework document at kernel.org.

Linux namespaces wrap a global system resource in an abstraction that makes it appear to the processes within the namespace that they have their own isolated instance of the global resource. Changes to the global resource are visible to other processes that are members of the namespace, but are invisible to other processes. Since kernel version 5.6, there are 8 kinds of namespaces (see namespaces(7), unshare(1), nsenter(1)).

As of Debian 11 Bullseye (2021), Debian uses unified cgroup hierarchy (a.k.a. cgroups-v2).

Usage examples of namespaces with cgroups to isolate their processes and to allow resource control are:

These functionalities can't be realized by Secțiune 4.1, „Autentificare normală Unix”. These advanced topics are mostly out-of-scope for this introductory document.