Chapter 4. Authentication

Table of Contents

4.1. Normal Unix authentication
4.2. Managing account and password information
4.3. Good password
4.4. Creating encrypted password
4.5. PAM and 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. Other access controls
4.6.1. sudo
4.6.2. PolicyKit
4.6.3. SELinux
4.6.4. Restricting access to some server services
4.7. Security of authentication
4.7.1. Secure password on the Internet
4.7.2. Secure Shell
4.7.3. Extra security measures for the Internet
4.7.4. Securing the root password

When a person (or a program) requests access to the system, authentication confirms the identity to be a trusted one.

[Warning] Warning

Configuration errors of PAM may lock you out of your own system. You must have a rescue CD handy or setup an alternative boot partition. To recover, boot the system with them and correct things from there.

Normal Unix authentication is provided by the pam_unix(8) module under the PAM (Pluggable Authentication Modules). Its 3 important configuration files, with ":" separated entries, are the following.


"/etc/passwd" contains the following.

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

As explained in passwd(5), each ":" separated entry of this file means the following.

  • Login name

  • Password specification entry

  • Numerical user ID

  • Numerical group ID

  • User name or comment field

  • User home directory

  • Optional user command interpreter

The second entry of "/etc/passwd" was used for the encrypted password entry. After the introduction of "/etc/shadow", this entry is used for the password specification entry.


"/etc/shadow" contains the following.

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

As explained in shadow(5), each ":" separated entry of this file means the following.

  • Login name

  • Encrypted password (The initial "$1$" indicates use of the MD5 encryption. The "*" indicates no login.)

  • Date of the last password change, expressed as the number of days since Jan 1, 1970

  • Number of days the user will have to wait before she will be allowed to change her password again

  • Number of days after which the user will have to change her password

  • Number of days before a password is going to expire during which the user should be warned

  • Number of days after a password has expired during which the password should still be accepted

  • Date of expiration of the account, expressed as the number of days since Jan 1, 1970

"/etc/group" contains the following.

group1:x:20:user1,user2

As explained in group(5), each ":" separated entry of this file means the following.

  • Group name

  • Encrypted password (not really used)

  • Numerical group ID

  • "," separated list of user names

[Note] Note

"/etc/gshadow" provides the similar function as "/etc/shadow" for "/etc/group" but is not really used.

[Note] Note

The actual group membership of a user may be dynamically added if "auth optional pam_group.so" line is added to "/etc/pam.d/common-auth" and set it in "/etc/security/group.conf". See pam_group(8).

[Note] Note

The base-passwd package contains an authoritative list of the user and the group: "/usr/share/doc/base-passwd/users-and-groups.html".

Here are few notable commands to manage account information.


You may need to have the root privilege for some functions to work. See crypt(3) for the password and data encryption.

[Note] Note

On the system set up with PAM and NSS as the Debian alioth machine, the content of local "/etc/passwd", "/etc/group" and "/etc/shadow" may not be actively used by the system. Above commands are valid even under such environment.

When creating an account during your system installation or with the passwd(1) command, you should choose a good password which consists of at least 6 to 8 characters including one or more characters from each of the following sets according to passwd(1).

  • Lower case alphabetics

  • Digits 0 through 9

  • Punctuation marks

[Warning] Warning

Do not choose guessable words for the password. Account name, social security number, phone number, address, birthday, name of your family members or pets, dictionary words, simple sequence of characters such as "12345" or "qwerty", … are all bad choice for the password.

There are independent tools to generate encrypted passwords with salt.


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.

[Note] Note

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".

[Note] Note

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

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-ldap and libnss-ldap 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".

    • Debian uses "/etc/pam_ldap.conf" as the configuration file for libpam-ldap and "/etc/pam_ldap.secret" as the file to store the password of the root.

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

    • Debian uses "/etc/libnss-ldap.conf" as the configuration file for libnss-ldap.

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

  • You may make libnss-ldap 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 pam_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.

[Note] Note

See Section 9.3.15, “Alt-SysRq key” for restricting the kernel secure attention key (SAK) feature.

[Tip] Tip

Under systemd, logind may be used to manage user logins. See systemd-logind(8).

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 Section 1.1.12, “sudo configuration”.

My usage of sudo for the single user system (see Section 1.1.12, “sudo configuration”) 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.

See polkit(8).

Security-Enhanced Linux (SELinux) is a framework to tighten privilege model tighter than the ordinary Unix-like security model with the mandatory access control (MAC) policies. The root power may be restricted under some conditions.

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 Section 3.2.3, “The runlevel management example”, Section 3.2.4, “The default parameter for each init script”, Section 4.5.1, “Configuration files accessed by PAM and NSS”, Section 3.2.8, “Network service initialization”, and Section 5.9, “Netfilter infrastructure”.

[Tip] Tip

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

[Tip] Tip

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.)

[Note] Note

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 Section 6.9, “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 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 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 Section 3.1.2, “Stage 2: the boot loader”) 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.

[Note] Note

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 Section 9.4.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 Section 9.8, “Data encryption tips”). You always need password to boot the system, though.