old-www/HOWTO/User-Authentication-HOWTO/x71.html

333 lines
7.0 KiB
HTML

<HTML
><HEAD
><TITLE
> How User Information is Stored on Your System
</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE=" User Authentication HOWTO
"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE=" Introduction
"
HREF="x40.html"><LINK
REL="NEXT"
TITLE=" PAM (Pluggable Authentication Modules)
"
HREF="x115.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>User Authentication HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x40.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x115.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="AEN71"
></A
>2. How User Information is Stored on Your System</H1
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN73"
></A
>2.1. <TT
CLASS="FILENAME"
>/etc/passwd</TT
></H2
><P
> On almost all linux distributions (and commercial *nixes as well), user information is stored in <TT
CLASS="FILENAME"
>/etc/passwd</TT
>, a text file which contains the user's login, their encrypted password, a unique numerical user id (called the uid), a numerical group id (called the gid), an optional comment field (usually containing such items as their real name, phone number, etc.), their home directory, and their preferred shell. A typical entry in <TT
CLASS="FILENAME"
>/etc/passwd</TT
> looks something like this:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
> pete:K3xcO1Qnx8LFN:1000:1000:Peter Hernberg,,,1-800-FOOBAR:/home/pete:/bin/bash
</PRE
></FONT
></TD
></TR
></TABLE
><P
> As you can see, it's pretty straight-forward. Each entry contains the six fields I described above, with each field separated by a colon. If this were as complex as user authentication got, there would be no need for this HOWTO.
</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN81"
></A
>2.2. Shadow passwords</H2
><P
> Looking at your <TT
CLASS="FILENAME"
>/etc/passwd</TT
>, it's likely that you actually saw something like this:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
> pete:x:1000:1000:Peter Hernberg,,,1-800-FOOBAR:/home/pete:/bin/bash
</PRE
></FONT
></TD
></TR
></TABLE
><P
> Where did the encrypted password go? Before I tell you where it went, a bit explanation is required.
</P
><P
> The <TT
CLASS="FILENAME"
>/etc/passwd</TT
> file, which contains information about all users, including their encrypted password, is readable by all users, making it possible for any user to get the encrypted password of everyone on the system. Though the passwords are encrypted, password-cracking programs are widely available. To combat this growing security threat, shadow passwords were developed.
</P
><P
> When a system has shadow passwords enabled, the password field in <TT
CLASS="FILENAME"
>/etc/passwd</TT
> is replaced by an "x" and the user's real encrypted password is stored in <TT
CLASS="FILENAME"
>/etc/shadow</TT
>. Because <TT
CLASS="FILENAME"
>/etc/shadow</TT
> is only readable by the root user, malicious users cannot crack their fellow users' passwords. Each entry in <TT
CLASS="FILENAME"
>/etc/shadow</TT
> contains the user's login, their encrypted password, and a number of fields relating to password expiration. A typical entry looks like this:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
> pete:/3GJllg1o4152:11009:0:99999:7:::
</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN95"
></A
>2.3. <TT
CLASS="FILENAME"
>/etc/group</TT
> and <TT
CLASS="FILENAME"
>/etc/gshadow</TT
></H2
><P
> Group information is stored in <TT
CLASS="FILENAME"
>/etc/group</TT
>. The format is similar to that of <TT
CLASS="FILENAME"
>/etc/passwd</TT
>, with the entries containing fields for the group name, password, numerical id (gid), and a comma-separated list of group members. An entry in <TT
CLASS="FILENAME"
>/etc/group</TT
> looks like this:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
> pasta:x:103:spagetti,fettucini,linguine,vermicelli
</PRE
></FONT
></TD
></TR
></TABLE
><P
> As you can see from the "x" in the password field, group passwords can be shadowed as well. Although groups almost never have their own passwords, it is worth noting that shadowed group password information is stored in <TT
CLASS="FILENAME"
>/etc/gshadow</TT
>.
</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN106"
></A
>2.4. MD5 encrypted passwords</H2
><P
> Traditionally, unix passwords were encrypted with the standard crypt() function. (For more information on the crypt() function, see the crypt(3) manpage.) As computers grew faster, passwords encrypted with this function became easier to crack. As the internet emerged, tools for distributing the task of password-cracking across multiple hosts became available. Many 'newer' distributions ship with the option of encrypting passwords with the stronger MD5 hash algorithm. (For more information on the MD5 hash algorithm, consult RFC 1321.) While MD5 passwords will not eliminate the threat of password cracking, they will make cracking your passwords much more difficult.
</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="AEN109"
></A
>2.5. Sifting through the mess</H2
><P
> As you can see, there are a number of different ways user authentication information can be stored on your system (shadow passwords without MD5 encryption, <TT
CLASS="FILENAME"
>/etc/passwd</TT
> passwords with MD5 encryption, etc.). How do programs like <SPAN
CLASS="APPLICATION"
>login</SPAN
> and <SPAN
CLASS="APPLICATION"
>su</SPAN
> know how to verify your password? Worse yet, what if you wanted to change the way passwords are stored on your system? How will programs that need your password know that passwords are stored differently? PAM is the answer.
</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="x40.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="x115.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Introduction</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>PAM (Pluggable Authentication Modules)</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>