Beginning Fedora 2

How Linux Stores User Account Information

As you ve seen, the User Manager makes it really easy to create user accounts and groups, and to define group membership. Having seen it in action, it s a good time to see where account information is stored in the filesystem. By taking a quick look at these files, you ll get a better understanding of what you achieved in the preceding examples, and it will prepare you for using the command line tools that you ll see later in this chapter.

Linux stores its local user account information in the text configuration files shown in the following table.

Configuration File

Purpose

/etc/passwd

Contains a list of local users and their data

/etc/shadow

Contains encrypted passwords and bookkeeping information such as account expiry

/etc/group

Defines groups and associated accounts

Note

There is a fourth file, /etc/gshadow , that we will not cover extensively here. It stores encrypted group passwords. You can find out more by reading the HOWTO file on this subject, which (in the current release) can be found at /usr/share/doc/shadow- utils -*/HOWTO .

User Accounts and Their Properties

To examine in better detail the properties of a user account on your system, you can take a look at your /etc/passwd file (using a text editor such as gedit or a CLI command such as cat ). The /etc/passwd file is essentially the user account database in which Linux stores valid accounts and related information about these accounts.

The following example includes details of the accounts we just created using the User Manager. Your /etc/passwd file will be similar in structure to the file excerpt shown here, although the exact details may be a little different:

root:x:0:0:Super User:/root:/bin/bash halt:x:7:0:Stop the System:/sbin:/sbin/halt eziodm:x:500:500:Pancrazio 'Ezio' de Mauro:/home/eziodm:/bin/bash kapils:x:501:501:Kapil Sharma:/home/kapils:/bin/bash deepakt:x:502:502:Deepak Thomas:/home/deepakt:/bin/bash

Each line of the /etc/passwd file is a single record in the user database and represents a single user. The administrator (root) account is usually the first user account defined in the file; it s followed by a number of system accounts , and finally the ordinary user accounts (such as the eziodm, kapils, and deepakt accounts here).

Each record is composed of a number of fields , which describe the properties of the user account. In this file, adjacent fields are separated by a colon (:). To get a better understanding of the purpose of each field, let s look, for example, at the third record (see Figure 7-10).

Figure 7-10

In fact, the eight-character limit for account names is a historic UNIX thing. Sticking to this maximum length is still considered the safest choice, especially when networking with older UNIX computers.

You can get more information with the man 5 passwd and man 5 shells commands from your terminal window or console screen.

User Account Passwords

As it happens, any user has read access to the /etc/passwd file ”indeed, this access is handy if, for example, you need to match an account name to its UID. But as previously mentioned, older versions of Linux stored account passwords in encrypted format in the second field of the /etc/passwd file. A consequence of this was that it was easy for users to access the encrypted versions of the passwords of other users.

Initially, this was not considered a security issue because the passwords were encrypted. However, the storage of encrypted passwords in /etc/passwd is no longer considered safe; as we explain in the next subsections, techniques now exist that make it much easier to guess a user s password given its encrypted form and knowledge of the encryption algorithm.

To plug this security hole, Fedora Core stores encrypted passwords in a different file ” /etc/shadow . This file is accessible to root only. While non-root users can still read from /etc/passwd , they do not have permission to read from /etc/shadow , and thus do not have access to encrypted passwords.

Password Encryption

While the account passwords are now stored safely in the restricted access /etc/shadow file, Linux still takes the precaution of storing them in encrypted format.

If you use root privileges to examine the contents of the /etc/shadow file, you ll see each encrypted password stored as an incomprehensible string of characters, like this:

$mWzQxFuT$EWnSiX5hmxiERbUpfwR5V0

Fedora Core never stores passwords in the clear text form in which the user enters them. Rather, it always encrypts them before storing them or working with them, in such a way that it is not easily possible (or even feasible ) to decipher the encrypted version and find out the original password.

In fact, once the password has been encrypted and stored in /etc/shadow , there will never be the need to decrypt it again. This is a key point: when a user logs in, the operating system verifies her identity by encrypting the submitted password and comparing it with the encrypted string contained in the /etc/shadow . If the two strings match, access is granted. It is this process that enables Linux to avoid ever having to decrypt passwords.

A Technique for Guessing Passwords

Unfortunately, the fact that a password is encrypted before storage is not enough to guarantee that it can t be discovered by other means. While it s very difficult to use decryption techniques to discover the original passwords, it is quite possible to use a brute force method to find out weak passwords. The power of modern computer hardware makes it possible to take large numbers of common passwords, encrypt them using the same algorithm used by the operating system, and check if the encrypted version is the same as the one stored in the password file.

This technique is often called a dictionary attack because the attacker can take large numbers of candidate passwords from a dictionary. A surprising number of passwords can be cracked in this way ”indeed, Chapter 10 takes a look at a program called crack, which uses this technique to crack passwords.

The existence of such techniques is the motivating factor behind the decision to place passwords in /etc/shadow , rather than /etc/passwd . Thus, users are prevented from stealing encrypted passwords and then trying to break the weak ones via a dictionary attack.

Note

Further discussion of cryptographic techniques is outside the scope of this chapter. However, cryptography is a fascinating science. If you re interested, you could start experimenting with the GNU Privacy Guard (GnuPG) ”install the gnupg package on your system, and then have a look at the gpg command. The gpg manual page will certainly be useful, providing information and lists of other documents.

A Sample /etc/shadow File

Examine the following few lines from a sample /etc/shadow file. This example contains the entries for the accounts added via the User Manager earlier in this chapter. Once again, your /etc/shadow will probably differ from this, although its structure will be similar:

root:$ekA$Kv55YOaIHDcPlI1q6igoQ0:11961:0:99999:7::: halt:*:11961:0:99999:7::: eziodm:$W/RgbXrI$OP9t9IyVmQyvPfxNLUFwQ1:12100:0:99999:7::: kapils:!!Q7Ci4g$CqbN8rdCBw4GmxDlouQ2q/:12100:0:99999:7::: deepakt:$sUejrHGF$I3cSo2TRmKIbN55wfLgfB1:12100:0:99999:7:::

Just like /etc/passwd , each line (or record ) represents a user, and adjacent fields are separated by a colon. Again, to understand the purpose of the fields in this file, let s look at the third line (see Figure 7-11).

Figure 7-11

To get more information about /etc/shadow , you can consult its manual page by typing man 5 shadow at your shell prompt.

Groups

A user can belong to many groups, but as you ve seen, /etc/passwd allows membership of only one group (the primary group ). Membership of additional groups must be specified in the /etc/groups file. This file is very similar in structure to the two you ve already seen. The following example shows the groups created earlier in this chapter:

root:x:0:root bin:x:1:root,bin,daemon daemon:x:2:root,bin,daemon eziodm:x:500: kapils:x:501: deepakt:x:502: authors:x:503:eziodm,kapils,deepakt

The structure is quite simple. Let s study the second line of this file to understand the fields (see Figure 7-12).

Figure 7-12

For more information about /etc/group , you can type man 5 group at your shell prompt.

Категории