xref: /freebsd/share/man/man5/passwd.5 (revision df7f5d4de4592a8948a25ce01e5bddfbb7ce39dc)
1.\" Copyright (c) 1988, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     From: @(#)passwd.5	8.1 (Berkeley) 6/5/93
33.\"	$Id: passwd.5,v 1.14 1997/03/12 14:05:36 mpp Exp $
34.\"
35.Dd September 29, 1994
36.Dt PASSWD 5
37.Os
38.Sh NAME
39.Nm passwd
40.Nd format of the password file
41.Sh DESCRIPTION
42The
43.Nm passwd
44files are files consisting of newline separated records, one per user,
45containing ten colon (``:'') separated fields.  These fields are as
46follows:
47.Pp
48.Bl -tag -width password -offset indent
49.It name
50User's login name.
51.It password
52User's
53.Em encrypted
54password.
55.It uid
56User's id.
57.It gid
58User's login group id.
59.It class
60User's login class.
61.It change
62Password change time.
63.It expire
64Account expiration time.
65.It gecos
66General information about the user.
67.It home_dir
68User's home directory.
69.It shell
70User's login shell.
71.El
72.Pp
73Lines whose first non-whitespace character is a pound-sign (#)
74are comments, and are ignored.  Blank lines which consist
75only of spaces, tabs or newlines are also ignored.
76.Pp
77The
78.Ar name
79field is the login used to access the computer account, and the
80.Ar uid
81field is the number associated with it.  They should both be unique
82across the system (and often across a group of systems) since they
83control file access.
84.Pp
85While it is possible to have multiple entries with identical login names
86and/or identical user id's, it is usually a mistake to do so.  Routines
87that manipulate these files will often return only one of the multiple
88entries, and that one by random selection.
89.Pp
90The login name must never begin with a hyphen (``-''); also, it is strongly
91suggested that neither upper-case characters or dots (``.'') be part
92of the name, as this tends to confuse mailers.  No field may contain a
93colon (``:'') as this has been used historically to separate the fields
94in the user database.
95.Pp
96The password field is the
97.Em encrypted
98form of the password.
99If the
100.Ar password
101field is empty, no password will be required to gain access to the
102machine.  This is almost invariably a mistake.
103Because these files contain the encrypted user passwords, they should
104not be readable by anyone without appropriate privileges.
105Administrative accounts have a password field containing an asterisk
106.Ql \&*
107which disallows normal logins.
108.Pp
109The group field is the group that the user will be placed in upon login.
110Although this system supports multiple groups (see
111.Xr groups 1 )
112this field nominates the user's primary groups.
113Secondary group memberships are selected in
114.Pa /etc/group .
115.Pp
116The
117.Ar class
118field is a key for a user's login class.
119Login classes are defined in
120.Xr login.conf 5 ,
121which is a
122.Xr termcap 5
123style database of user attributes, accounting, resource and
124environment settings.
125.Pp
126The
127.Ar change
128field is the number in seconds,
129.Dv GMT ,
130from the epoch, until the
131password for the account must be changed.
132This field may be left empty or set to 0 to turn off the
133password aging feature.
134.Pp
135The
136.Ar expire
137field is the number in seconds,
138.Dv GMT ,
139from the epoch, until the
140account expires.
141This field may be left empty or set to 0 to turn off the account
142aging feature.
143.Pp
144The
145.Ar gecos
146field normally contains comma (``,'') separated subfields as follows:
147.Pp
148.Bd -unfilled -offset indent
149fullname		user's full name
150office		user's office number
151wphone		user's work phone number
152hphone		user's home phone number
153.Ed
154.Pp
155This information is used by the
156.Xr finger 1
157program, and the first field used by the system mailer.
158If an ampersand
159.Ql \&&
160character appears within the fullname field, programs which
161use this field will substitute it with a capitalized version
162of the account's login name.
163.Pp
164The user's home directory is the full
165.Tn UNIX
166path name where the user
167will be placed on login.
168.Pp
169The shell field is the command interpreter the user prefers.
170If there is nothing in the
171.Ar shell
172field, the Bourne shell
173.Pq Pa /bin/sh
174is assumed.
175For security reasons, if the shell is set to a script that disallows
176access to the system (the
177.Xr nologin 8
178script, for example), care should be taken not to import any environment
179variables.  With
180.Xr sh 1 ,
181this can be done by specifying the
182.Fl p
183flag.
184Check the specific shell documentation to determine how this is
185done with other shells.
186.Sh YP/NIS INTERACTION
187.Ss Enabling access to NIS passwd data
188The system administrator can configure FreeBSD to use NIS/YP for
189its password information by adding special records to the
190.Pa /etc/master.passwd
191file. These entries should be added with
192.Xr vipw 8
193so that the changes can be properly merged with the hashed
194password databases and the
195.Pa /etc/passwd
196file (
197.Pa /etc/passwd
198should never be edited manually). Alternatively, the administrator
199can modify
200.Pa /etc/master.passwd
201in some other way and then manually update the password databases with
202.Xr pwd_mkdb 8 .
203.Pp
204The simplest way to activate NIS is to add an empty record
205with only a plus sign (`+') in the name field, such as this:
206.Bd -literal -offset indent
207+:::::::::
208
209.Ed
210The `+' will tell the
211.Xr getpwent 3
212routines in FreeBSD's standard C library to begin using the NIS passwd maps
213for lookups.
214.Pp
215Note that the entry shown above is known as a
216.Pa wildcard
217entry, because it matches all users (the `+' without any other information
218matches everybody) and allows all NIS password data to be retrieved
219unaltered. However, by
220specifying a username or netgroup next to the `+' in the NIS
221entry, the administrator can affect what data is extracted from the
222NIS passwd maps and how it is interpreted. Here are a few example
223records that illustrate this feature (note that you can have several
224NIS entries in a single
225.Pa master.passwd
226file):
227.Bd -literal -offset indent
228-mitnick:::::::::
229+@staff:::::::::
230+@permitted-users:::::::::
231+dennis:::::::::
232+ken:::::::::/bin/csh
233+@rejected-users::32767:32767::::::/bin/false
234
235.Ed
236Specific usernames are listed explicitly while netgroups are signified
237by a preceding `@'. In the above example, users in the ``staff'' and
238``permitted-users'' netgroups will have their password information
239read from NIS and used unaltered. In other words, they will be allowed
240normal access to the machine. Users ``ken'' and ``dennis,'' who have
241been named explicitly rather than through a netgroup, will also have
242their password data read from NIS, _except_ that user ``ken'' will
243have his shell remapped to
244.Pa /bin/csh .
245This means that value for his shell specified in the NIS password map
246will be overridden by the value specified in the special NIS entry in
247the local
248.Pa master.passwd
249file. User ``ken'' may have been assigned the csh shell because his
250NIS password entry specified a different shell that may not be
251installed on the client machine for political or technical reasons.
252Meanwhile, users in the ``rejected-users'' netgroup are prevented
253from logging in because their UIDs, GIDs and shells have been overridden
254with invalid values.
255.Pp
256User ``mitnick'' will be be ignored entirely because his entry is
257specified with a `-' instead of a `+'. A minus entry can be used
258to block out certain NIS password entries completely; users who's
259password data has been excluded in this way are not recognized by
260the system at all. (Any overrides specified with minus entries are
261also ignored since there is no point in processing override information
262for a user that the system isn't going to recognize in the first place.)
263In general, a minus entry is used to specifically exclude a user
264who might otherwise be granted access because he happens to be a
265member of an authorized netgroup. For example, if ``mitnick'' is
266a member of the ``permitted-users'' netgroup and must, for whatever
267the reason, be permitted to remain in that netgroup (possibly to
268retain access to other machines within the domain), the administrator
269can still deny him access to a particular system with a minus entry.
270Also, it is sometimes easier to explicitly list those users who aren't
271allowed access rather than generate a possibly complicated list of
272users who are allowed access and omit the rest.
273.Pp
274Note that the plus and minus entries are evaluated in order from
275first to last with the first match taking precedence. This means
276that the system will only use the first entry which matches a particular user.
277If, for instance, we have a user ``foo'' who is a member of both the ``staff''
278netgroup and the ``rejected-users'' netgroup, he will be admitted to
279the system because the above example lists the entry for ``staff''
280before the entry for ``rejected-users.'' If we reversed the order,
281user ``foo'' would be flagged as a ``rejected-user'' instead and
282denied access.
283.Pp
284Lastly, any NIS password database records that do not match against
285at least one of the users or netgroups specified by the NIS access
286entries in the
287.Pa /etc/master.passwd
288file will be ignored (along with any users specified using minus
289entries). In our example shown above, we do not have a wildcard
290entry at the end of the list; therefore, the system will not recognize
291anyone except
292``ken,'' ``dennis,'' the ``staff'' netgroup and the ``permitted-users''
293netgroup as authorized users. The ``rejected-users'' netgroup will
294be recognized but all members will have their shells remapped and
295therefore be denied access.
296All other NIS password records
297will be ignored. The administrator may add a wildcard entry to the
298end of the list such as:
299.Bd -literal -offset indent
300+:::::::::/usr/local/bin/go_away
301
302.Ed
303This entry acts as a catch-all for all users that don't match against
304any of the other entries.
305.Pa /usr/local/bin/go_away
306can be a short shell script or program
307that prints a message telling the user that he is not allowed access
308to the system. This technique is sometimes useful when it is
309desirable to have the system be able to recognize all users in a
310particular NIS domain without necessarily granting them login access.
311See the above text on the shell field regarding security concerns when using
312a shell script as the login shell.
313.Pp
314The primary use of this
315.Pa override
316feature is to permit the administrator
317to enforce access restrictions on NIS client systems. Users can be
318granted access to one group of machines and denied access to other
319machines simply by adding or removing them from a particular netgroup.
320Since the netgroup database can also be accessed via NIS, this allows
321access restrictions to be administered from a single location, namely
322the NIS master server; once a host's access list has been set in
323.Pa /etc/master.passwd ,
324it need not be modified again unless new netgroups are created.
325.Sh NOTES
326.Ss Shadow passwords through NIS
327FreeBSD uses a shadow password scheme: users' encrypted passwords
328are stored only in
329.Pa /etc/master.passwd
330and
331.Pa /etc/spwd.db ,
332which are readable and writable only by the superuser. This is done
333to prevent users from running the encrypted passwords through
334password-guessing programs and gaining unauthorized access to
335other users' accounts. NIS does not support a standard means of
336password shadowing, which implies that placing your password data
337into the NIS passwd maps totally defeats the security of FreeBSD's
338password shadowing system.
339.Pp
340FreeBSD provides a few special features to help get around this
341problem. It is possible to implement password shadowing between
342FreeBSD NIS clients and FreeBSD NIS servers. The
343.Xr getpwent 3
344routines will search for a
345.Pa master.passwd.byname
346and
347.Pa master.passwd.byuid
348maps which should contain the same data found in the
349.Pa /etc/master.passwd
350file. If the maps exist, FreeBSD will attempt to use them for user
351authentication instead of the standard
352.Pa passwd.byname
353and
354.Pa passwd.byuid
355maps. FreeBSD's
356.Xr ypserv 8
357will also check client requests to make sure they originate on a
358privileged port. Since only the superuser is allowed to bind to
359a privileged port, the server can tell if the requesting user
360is the superuser; all requests from non-privileged users to access
361the
362.Pa master.passwd
363maps will be refused. Since all user authentication programs run
364with superuser privilege, they should have the required access to
365users' encrypted password data while normal users will only
366be allowed access to the standard
367.Pa passwd
368maps which contain no password information.
369.Pp
370Note that this feature cannot be used in an environment with
371non-FreeBSD systems. Note also that a truly determined user with
372unrestricted access to your network could still compromise the
373.Pa master.passwd
374maps.
375.Ss UID and GID remapping with NIS overrides
376Unlike SunOS and other operating systems that use Sun's NIS code,
377FreeBSD allows the user to override
378.Pa all
379of the fields in a user's NIS
380.Pa passwd
381entry.
382For example, consider the following
383.Pa /etc/master.passwd
384entry:
385.Bd -literal -offset indent
386+@foo-users:???:666:666:0:0:0:Bogus user:/home/bogus:/bin/bogus
387
388.Ed
389This entry will cause all users in the `foo-users' netgroup to
390have
391.Pa all
392of their password information overridden, including UIDs,
393GIDs and passwords. The result is that all `foo-users' will be
394locked out of the system, since their passwords will be remapped
395to invalid values.
396.Pp
397This is important to remember because most people are accustomed to
398using an NIS wildcard entry that looks like this:
399.Bd -literal -offset indent
400+:*:0:0:::
401
402.Ed
403This often leads to new FreeBSD administrators choosing NIS entries for their
404.Pa master.passwd
405files that look like this:
406.Bd -literal -offset indent
407+:*:0:0::::::
408
409.Ed
410Or worse, this
411.Bd -literal -offset indent
412+::0:0::::::
413
414.Ed
415.Pa DO _NOT_ PUT ENTRIES LIKE THIS IN YOUR
416.Nm master.passwd
417.Pa FILE!!
418The first tells FreeBSD to remap all passwords to `*' (which
419will prevent anybody from logging in) and to remap all UIDs and GIDs
420to 0 (which will make everybody appear to be the superuser). The
421second case just maps all UIDs and GIDs to 0, which means that
422.Pa all users will appear to be root!
423.Pp
424.Ss Compatibility of NIS override evaluation
425When Sun originally added NIS support to their
426.Xr getpwent 3
427routines, they took into account the fact that the SunOS password
428.Pa /etc/passwd
429file is in plain ASCII format. The SunOS documentation claims that
430adding a '+' entry to the password file causes the contents of
431the NIS password database to be 'inserted' at the position in
432the file where the '+' entry appears. If, for example, the
433administrator places the +:::::: entry in the middle of
434.Pa /etc/passwd,
435then the entire contents of the NIS password map would appear
436as though it had been copied into the middle of the password
437file. If the administrator places the +:::::: entry at both the
438middle and the end of
439.Pa /etc/passwd ,
440then the NIS password map would appear twice: once in the middle
441of the file and once at the end. (By using override entries
442instead of simple wildcards, other combinations could be achieved.)
443.Pp
444By contrast, FreeBSD does not have a single ASCII password file: it
445has a hashed password database. This database does not have an
446easily-defined beginning, middle or end, which makes it very hard
447to design a scheme that is 100% compatible with SunOS. For example,
448the
449.Fn getpwnam
450and
451.Fn getpwuid
452functions in FreeBSD are designed to do direct queries to the
453hash database rather than a linear search. This approach is faster
454on systems where the password database is large. However, when
455using direct database queries, the system does not know or care
456about the order of the original password file, and therefore
457it cannot easily apply the same override logic used by SunOS.
458.Pp
459Instead, FreeBSD groups all the NIS override entries together
460and constructs a filter out of them. Each NIS password entry
461is compared against the override filter exactly once and
462treated accordingly: if the filter allows the entry through
463unaltered, it's treated unaltered; if the filter calls for remapping
464of fields, then fields are remapped; if the filter calls for
465explicit exclusion (i.e. the entry matches a '-' override),
466the entry is ignored; if the entry doesn't match against any
467of the filter specifications, it's discarded.
468.Pp
469Again, note that the NIS '+' and '-' entries
470themselves are handled in the order in which they were specified
471in the
472.Pa /etc/master.passwd
473file since doing otherwise would lead to unpredicable behavior.
474.Pp
475The end result is that FreeBSD's provides a very close approximation
476of SunOS's behavior while maintaining the database paradigm, though the
477.Xr getpwent 3
478functions do behave somewhat differently that their SunOS counterparts.
479The primary differences are:
480.Bl -bullet -offset indent
481.It
482Each NIS password map record can be mapped into the password
483local password space only once.
484.It
485The placement of the NIS '+' and '-' entries does not necessarily
486affect where NIS password records will be mapped into
487the password space.
488.El
489.Pp
490In %99 of all FreeBSD configurations, NIS client behavior will be
491indistinguishable from that of SunOS or other similar systems. Even
492so, users should be aware of these architectural differences.
493.Pp
494.Ss Using groups instead of netgroups for NIS overrides
495FreeBSD offers the capability to do override matching based on
496user groups rather than netgroups. If, for example, an NIS entry
497is specified as:
498.Bd -literal -offset indent
499+@operator:::::::::
500
501.Ed
502the system will first try to match users against a netgroup called
503`operator.' If an `operator' netgroup doesn't exist, the system
504will try to match users against the normal `operator' group
505instead.
506.Ss Changes in behavior from older versions of FreeBSD
507There have been several bug fixes and improvements in FreeBSD's
508NIS/YP handling, some of which have caused changes in behavior.
509While the behavior changes are generally positive, it is important
510that users and system administrators be aware of them:
511.Bl -enum -offset indent
512.It
513In versions prior to 2.0.5, reverse lookups (i.e. using
514.Fn getpwuid )
515would not have overrides applied, which is to say that it
516was possible for
517.Fn getpwuid
518to return a login name that
519.Fn getpwnam
520would not recognize. This has been fixed: overrides specified
521in
522.Pa /etc/master.passwd
523now apply to all
524.Xr getpwent 3
525functions.
526.It
527Prior to FreeBSD 2.0.5, netgroup overrides did not work at
528all, largely because FreeBSD did not have support for reading
529netgroups through NIS. Again, this has been fixed, and
530netgroups can be specified just as in SunOS and similar NIS-capable
531systems.
532.It
533FreeBSD now has NIS server capabilities and supports the use
534of
535.Pa master.passwd
536NIS maps in addition to the standard Sixth Edition format
537.Pa passwd
538maps.
539This means that you can specify change, expiration and class
540information through NIS, provided you use a FreeBSD system as
541the NIS server.
542.El
543.Sh FILES
544.Bl -tag -width /etc/master.passwd -compact
545.It Pa /etc/passwd
546ASCII password file, with passwords removed
547.It Pa /etc/pwd.db
548.Xr db 3 -format
549password database, with passwords removed
550.It Pa /etc/master.passwd
551ASCII password file, with passwords intact
552.It Pa /etc/spwd.db
553.Xr db 3 -format
554password database, with passwords intact
555.El
556.Sh SEE ALSO
557.Xr chpass 1 ,
558.Xr login 1 ,
559.Xr passwd 1 ,
560.Xr getpwent 3 ,
561.Xr login_getclass 3 ,
562.Xr yp 4 ,
563.Xr login.conf 5 ,
564.Xr adduser 8 ,
565.Xr pwd_mkdb 8 ,
566.Xr vipw 8
567.Sh BUGS
568User information should (and eventually will) be stored elsewhere.
569.Pp
570The YP/NIS password database makes encrypted passwords visible to
571ordinary users, thus making password cracking easier unless you use
572shadow passwords with the
573.Pa master.passwd
574maps and FreeBSD's
575.Xr ypserv 8
576server.
577.Pp
578Unless you're using FreeBSD's
579.Xr ypserv 8 ,
580which supports the use of
581.Pa master.passwd
582type maps,
583the YP/NIS password database will be in old-style (Sixth Edition) format,
584which means that site-wide values for user login class, password
585expiration date, and other fields present in the current format
586will not be available when a FreeBSD system is used as a client with
587a standard NIS server.
588.Sh COMPATIBILITY
589The password file format has changed since
590.Bx 4.3 .
591The following awk script can be used to convert your old-style password
592file into a new style password file.
593The additional fields
594.Dq class ,
595.Dq change
596and
597.Dq expire
598are added, but are turned off by default.
599Class is currently not implemented, but change and expire are; to set them,
600use the current day in seconds from the epoch + whatever number of seconds
601of offset you want.
602.Bd -literal -offset indent
603BEGIN { FS = ":"}
604{ print $1 ":" $2 ":" $3 ":" $4 "::0:0:" $5 ":" $6 ":" $7 }
605.Ed
606.Sh HISTORY
607A
608.Nm
609file format appeared in
610.At v6 .
611The YP/NIS functionality is modeled after
612.Tn SunOS
613and first appeared in
614.Tn FreeBSD
6151.1.  The override capability is new in
616.Fx 2.0 .
617The override capability was updated to properly support netgroups
618in
619.Fx 2.0.5 .
620Support for comments first appeared in
621.Fx 3.0 .
622