xref: /freebsd/share/man/man5/passwd.5 (revision b601c69bdbe8755d26570261d7fd4c02ee4eff74)
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.\" $FreeBSD$
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
46.Pq Ql \&:
47separated fields.  These fields are as
48follows:
49.Pp
50.Bl -tag -width password -offset indent
51.It name
52User's login name.
53.It password
54User's
55.Em encrypted
56password.
57.It uid
58User's id.
59.It gid
60User's login group id.
61.It class
62User's login class.
63.It change
64Password change time.
65.It expire
66Account expiration time.
67.It gecos
68General information about the user.
69.It home_dir
70User's home directory.
71.It shell
72User's login shell.
73.El
74.Pp
75Lines whose first non-whitespace character is a pound-sign (#)
76are comments, and are ignored.  Blank lines which consist
77only of spaces, tabs or newlines are also ignored.
78.Pp
79The
80.Ar name
81field is the login used to access the computer account, and the
82.Ar uid
83field is the number associated with it.  They should both be unique
84across the system (and often across a group of systems) since they
85control file access.
86.Pp
87While it is possible to have multiple entries with identical login names
88and/or identical uids, it is usually a mistake to do so.  Routines
89that manipulate these files will often return only one of the multiple
90entries, and that one by random selection.
91.Pp
92The login name must never begin with a hyphen
93.Pq Ql \&- ;
94also, it is strongly
95suggested that neither upper-case characters nor dots
96.Pq Ql \&.
97be part
98of the name, as this tends to confuse mailers.
99.Pp
100The password field is the
101.Em encrypted
102form of the password.
103If the
104.Ar password
105field is empty, no password will be required to gain access to the
106machine.  This is almost invariably a mistake.
107Because these files contain the encrypted user passwords, they should
108not be readable by anyone without appropriate privileges.
109Administrative accounts have a password field containing an asterisk
110.Ql \&*
111which disallows normal logins.
112.Pp
113The group field is the group that the user will be placed in upon login.
114Although this system supports multiple groups (see
115.Xr groups 1 )
116this field indicates the user's primary group.
117Secondary group memberships are selected in
118.Pa /etc/group .
119.Pp
120The
121.Ar class
122field is a key for a user's login class.
123Login classes are defined in
124.Xr login.conf 5 ,
125which is a
126.Xr termcap 5
127style database of user attributes, accounting, resource and
128environment settings.
129.Pp
130The
131.Ar change
132field is the number in seconds,
133.Dv GMT ,
134from the epoch, until the
135password for the account must be changed.
136This field may be left empty or set to 0 to turn off the
137password aging feature.
138.Pp
139The
140.Ar expire
141field is the number in seconds,
142.Dv GMT ,
143from the epoch, until the
144account expires.
145This field may be left empty or set to 0 to turn off the account
146aging feature.
147.Pp
148The
149.Ar gecos
150field normally contains comma
151.Pq Ql \&,
152separated subfields as follows:
153.Pp
154.Bl -bullet -compact -offset indent
155.It
156user's full name
157.It
158user's office location
159.It
160user's work phone number
161.It
162user's home phone number
163.El
164.Pp
165This information is used by the
166.Xr finger 1
167program, and the first field used by the system mailer.
168If an ampersand
169.Pq Ql \&&
170character appears within the fullname field, programs that
171use this field will substitute it with a capitalized version
172of the account's login name.
173.Pp
174The user's home directory is the full
175.Tn UNIX
176path name where the user
177will be placed on login.
178.Pp
179The shell field is the command interpreter the user prefers.
180If there is nothing in the
181.Ar shell
182field, the Bourne shell
183.Pq Pa /bin/sh
184is assumed.
185For security reasons, if the shell is set to a script that disallows
186access to the system (the
187.Xr nologin 8
188script, for example), care should be taken not to import any environment
189variables.  With
190.Xr sh 1 ,
191this can be done by specifying the
192.Fl p
193flag.
194Check the specific shell documentation to determine how this is
195done with other shells.
196.Sh YP/NIS INTERACTION
197.Ss Enabling access to NIS passwd data
198The system administrator can configure
199.Tn FreeBSD
200to use NIS/YP for
201its password information by adding special records to the
202.Pa /etc/master.passwd
203file.
204These entries should be added with
205.Xr vipw 8
206so that the changes can be properly merged with the hashed
207password databases and the
208.Pa /etc/passwd
209file (
210.Pa /etc/passwd
211should never be edited manually). Alternatively, the administrator
212can modify
213.Pa /etc/master.passwd
214in some other way and then manually update the password databases with
215.Xr pwd_mkdb 8 .
216.Pp
217The simplest way to activate NIS is to add an empty record
218with only a plus sign
219.Pq Ql \&+
220in the name field, such as this:
221.Bd -literal -offset indent
222+:::::::::
223
224.Ed
225The
226.Ql \&+
227will tell the
228.Xr getpwent 3
229routines in
230.Tn FreeBSD Ns 's
231standard C library to begin using the NIS passwd maps
232for lookups.
233.Pp
234Note that the entry shown above is known as a
235.Em wildcard
236entry, because it matches all users (the
237.Ql \&+
238without any other information
239matches everybody) and allows all NIS password data to be retrieved
240unaltered.
241However, by
242specifying a username or netgroup next to the
243.Ql \&+
244in the NIS
245entry, the administrator can affect what data are extracted from the
246NIS passwd maps and how it is interpreted.
247Here are a few example
248records that illustrate this feature (note that you can have several
249NIS entries in a single
250.Pa master.passwd
251file):
252.Bd -literal -offset indent
253-mitnick:::::::::
254+@staff:::::::::
255+@permitted-users:::::::::
256+dennis:::::::::
257+ken:::::::::/bin/csh
258+@rejected-users::32767:32767::::::/bin/false
259
260.Ed
261Specific usernames are listed explicitly while netgroups are signified
262by a preceding
263.Ql \&@ .
264In the above example, users in the
265.Dq staff
266and
267.Dq permitted-users
268netgroups will have their password information
269read from NIS and used unaltered.
270In other words, they will be allowed
271normal access to the machine.
272Users
273.Dq ken
274and
275.Dq dennis ,
276who have
277been named explicitly rather than through a netgroup, will also have
278their password data read from NIS,
279.Em except
280that user
281.Dq ken
282will have his shell remapped to
283.Pa /bin/csh .
284This means that value for his shell specified in the NIS password map
285will be overridden by the value specified in the special NIS entry in
286the local
287.Pa master.passwd
288file.
289User
290.Dq ken
291may have been assigned the csh shell because his
292NIS password entry specified a different shell that may not be
293installed on the client machine for political or technical reasons.
294Meanwhile, users in the
295.Dq rejected-users
296netgroup are prevented
297from logging in because their UIDs, GIDs and shells have been overridden
298with invalid values.
299.Pp
300User
301.Dq mitnick
302will be be ignored entirely because his entry is
303specified with a
304.Ql \&-
305instead of a
306.Ql \&+ .
307A minus entry can be used
308to block out certain NIS password entries completely; users whose
309password data has been excluded in this way are not recognized by
310the system at all.
311(Any overrides specified with minus entries are
312also ignored since there is no point in processing override information
313for a user that the system isn't going to recognize in the first place.)
314In general, a minus entry is used to specifically exclude a user
315who might otherwise be granted access because he happens to be a
316member of an authorized netgroup.
317For example, if
318.Dq mitnick
319is
320a member of the
321.Dq permitted-users
322netgroup and must, for whatever
323the reason, be permitted to remain in that netgroup (possibly to
324retain access to other machines within the domain), the administrator
325can still deny him access to a particular system with a minus entry.
326Also, it is sometimes easier to explicitly list those users who are not
327allowed access rather than generate a possibly complicated list of
328users who are allowed access and omit the rest.
329.Pp
330Note that the plus and minus entries are evaluated in order from
331first to last with the first match taking precedence.
332This means
333the system will only use the first entry that matches a particular user.
334If, using the same example, there is a user
335.Dq foo
336who is a member of both the
337.Dq staff
338netgroup and the
339.Dq rejected-users
340netgroup, he will be admitted to
341the system because the above example lists the entry for
342.Dq staff
343before the entry for
344.Dq rejected-users .
345If the order were reversed,
346user
347.Dq foo
348would be flagged as a
349.Dq rejected-user
350instead and denied access.
351.Pp
352Lastly, any NIS password database records that do not match against
353at least one of the users or netgroups specified by the NIS access
354entries in the
355.Pa /etc/master.passwd
356file will be ignored (along with any users specified using minus
357entries). In our example shown above, we do not have a wildcard
358entry at the end of the list; therefore, the system will not recognize
359anyone except
360.Dq ken ,
361.Dq dennis ,
362the
363.Dq staff
364netgroup, and the
365.Dq permitted-users
366netgroup as authorized users.
367The
368.Dq rejected-users
369netgroup will
370be recognized but all members will have their shells remapped and
371therefore be denied access.
372All other NIS password records
373will be ignored.
374The administrator may add a wildcard entry to the
375end of the list such as:
376.Bd -literal -offset indent
377+:::::::::/sbin/nologin
378
379.Ed
380This entry acts as a catch-all for all users that don't match against
381any of the other entries.
382This technique is sometimes useful when it is
383desirable to have the system be able to recognize all users in a
384particular NIS domain without necessarily granting them login access.
385See the description of the shell field regarding security concerns when using
386a shell script as the login shell.
387.Pp
388The primary use of this
389.Pa override
390feature is to permit the administrator
391to enforce access restrictions on NIS client systems.
392Users can be
393granted access to one group of machines and denied access to other
394machines simply by adding or removing them from a particular netgroup.
395Since the netgroup database can also be accessed via NIS, this allows
396access restrictions to be administered from a single location, namely
397the NIS master server; once a host's access list has been set in
398.Pa /etc/master.passwd ,
399it need not be modified again unless new netgroups are created.
400.Sh NOTES
401.Ss Shadow passwords through NIS
402.Tn FreeBSD
403uses a shadow password scheme: users' encrypted passwords
404are stored only in
405.Pa /etc/master.passwd
406and
407.Pa /etc/spwd.db ,
408which are readable and writable only by the superuser.
409This is done
410to prevent users from running the encrypted passwords through
411password-guessing programs and gaining unauthorized access to
412other users' accounts.
413NIS does not support a standard means of
414password shadowing, which implies that placing your password data
415into the NIS passwd maps totally defeats the security of
416.Tn FreeBSD Ns 's
417password shadowing system.
418.Pp
419.Tn FreeBSD
420provides a few special features to help get around this
421problem.
422It is possible to implement password shadowing between
423.Tn FreeBSD
424NIS clients and
425.Tn FreeBSD
426NIS servers.
427The
428.Xr getpwent 3
429routines will search for a
430.Pa master.passwd.byname
431and
432.Pa master.passwd.byuid
433maps which should contain the same data found in the
434.Pa /etc/master.passwd
435file.
436If the maps exist,
437.Tn FreeBSD
438will attempt to use them for user
439authentication instead of the standard
440.Pa passwd.byname
441and
442.Pa passwd.byuid
443maps.
444.Tn FreeBSD Ns 's
445.Xr ypserv 8
446will also check client requests to make sure they originate on a
447privileged port.
448Since only the superuser is allowed to bind to
449a privileged port, the server can tell if the requesting user
450is the superuser; all requests from non-privileged users to access
451the
452.Pa master.passwd
453maps will be refused.
454Since all user authentication programs run
455with superuser privilege, they should have the required access to
456users' encrypted password data while normal users will only
457be allowed access to the standard
458.Pa passwd
459maps which contain no password information.
460.Pp
461Note that this feature cannot be used in an environment with
462.No non- Ns Tn FreeBSD
463systems.
464Note also that a truly determined user with
465unrestricted access to your network could still compromise the
466.Pa master.passwd
467maps.
468.Ss UID and GID remapping with NIS overrides
469Unlike
470.Tn SunOS
471and other operating systems that use Sun's NIS code,
472.Tn FreeBSD
473allows the user to override
474.Pa all
475of the fields in a user's NIS
476.Pa passwd
477entry.
478For example, consider the following
479.Pa /etc/master.passwd
480entry:
481.Bd -literal -offset indent
482+@foo-users:???:666:666:0:0:0:Bogus user:/home/bogus:/bin/bogus
483
484.Ed
485This entry will cause all users in the `foo-users' netgroup to
486have
487.Pa all
488of their password information overridden, including UIDs,
489GIDs and passwords.
490The result is that all `foo-users' will be
491locked out of the system, since their passwords will be remapped
492to invalid values.
493.Pp
494This is important to remember because most people are accustomed to
495using an NIS wildcard entry that looks like this:
496.Bd -literal -offset indent
497+:*:0:0:::
498
499.Ed
500This often leads to new
501.Tn FreeBSD
502administrators choosing NIS entries for their
503.Pa master.passwd
504files that look like this:
505.Bd -literal -offset indent
506+:*:0:0::::::
507
508.Ed
509Or worse, this
510.Bd -literal -offset indent
511+::0:0::::::
512
513.Ed
514.Sy DO _NOT_ PUT ENTRIES LIKE THIS IN YOUR
515.Sy Pa master.passwd
516.Sy FILE!!
517The first tells
518.Tn FreeBSD
519to remap all passwords to
520.Ql \&*
521(which
522will prevent anybody from logging in) and to remap all UIDs and GIDs
523to 0 (which will make everybody appear to be the superuser). The
524second case just maps all UIDs and GIDs to 0, which means that
525all users will appear to be root!
526.Pp
527.Ss Compatibility of NIS override evaluation
528When Sun originally added NIS support to their
529.Xr getpwent 3
530routines, they took into account the fact that the
531.Tn SunOS
532password
533.Pa /etc/passwd
534file is in plain
535.Tn ASCII
536format.
537The
538.Tn SunOS
539documentation claims that
540adding a
541.Ql \&+
542entry to the password file causes the contents of
543the NIS password database to be
544.Dq inserted
545at the position in the file where the
546.Ql \&+
547entry appears.
548If, for example, the
549administrator places a
550.Ql \&+::::::
551entry in the middle of
552.Pa /etc/passwd ,
553then the entire contents of the NIS password map would appear
554as though it had been copied into the middle of the password
555file.
556If the administrator places
557.Ql \&+::::::
558entries at both the middle and the end of
559.Pa /etc/passwd ,
560then the NIS password map would appear twice: once in the middle
561of the file and once at the end.
562(By using override entries
563instead of simple wildcards, other combinations could be achieved.)
564.Pp
565By contrast,
566.Fx
567does not have a single
568.Tn ASCII
569password file: it
570has a hashed password database.
571This database does not have an
572easily-defined beginning, middle or end, which makes it very hard
573to design a scheme that is 100% compatible with
574.Tn SunOS .
575For example,
576the
577.Fn getpwnam
578and
579.Fn getpwuid
580functions in
581.Tn FreeBSD
582are designed to do direct queries to the
583hash database rather than a linear search.
584This approach is faster
585on systems where the password database is large.
586However, when
587using direct database queries, the system does not know or care
588about the order of the original password file, and therefore
589it cannot easily apply the same override logic used by
590.Tn SunOS .
591.Pp
592Instead,
593.Tn FreeBSD
594groups all the NIS override entries together
595and constructs a filter out of them.
596Each NIS password entry
597is compared against the override filter exactly once and
598treated accordingly: if the filter allows the entry through
599unaltered, it's treated unaltered; if the filter calls for remapping
600of fields, then fields are remapped; if the filter calls for
601explicit exclusion (i.e., the entry matches a
602.Ql \&-
603override), the entry is ignored; if the entry doesn't match against any
604of the filter specifications, it's discarded.
605.Pp
606Again, note that the NIS
607.Ql \&+
608and
609.Ql \&-
610entries themselves are handled in the order in which they were specified
611in the
612.Pa /etc/master.passwd
613file, since doing otherwise would lead to unpredictable behavior.
614.Pp
615The end result is that
616.Tn FreeBSD Ns 's
617provides a very close approximation
618of
619.Tn SunOS Ns 's
620behavior while maintaining the database paradigm, though the
621.Xr getpwent 3
622functions do behave somewhat differently from their
623.Tn SunOS
624counterparts.
625The primary differences are:
626.Bl -bullet -offset indent
627.It
628Each NIS password map record can be mapped into the password
629local password space only once.
630.It
631The placement of the NIS
632.Ql \&+
633and
634.Ql \&-
635entries does not necessarily
636affect where NIS password records will be mapped into
637the password space.
638.El
639.Pp
640In 99% of all
641.Tn FreeBSD
642configurations, NIS client behavior will be
643indistinguishable from that of
644.Tn SunOS
645or other similar systems.
646Even
647so, users should be aware of these architectural differences.
648.Pp
649.Ss Using groups instead of netgroups for NIS overrides
650.Tn FreeBSD
651offers the capability to do override matching based on
652user groups rather than netgroups.
653If, for example, an NIS entry
654is specified as:
655.Bd -literal -offset indent
656+@operator:::::::::
657
658.Ed
659the system will first try to match users against a netgroup called
660.Ql operator .
661If an
662.Ql operator
663netgroup doesn't exist, the system
664will try to match users against the normal
665.Ql operator
666group instead.
667.Ss Changes in behavior from older versions of FreeBSD
668There have been several bug fixes and improvements in
669.Tn FreeBSD Ns 's
670NIS/YP handling, some of which have caused changes in behavior.
671While the behavior changes are generally positive, it is important
672that users and system administrators be aware of them:
673.Bl -enum -offset indent
674.It
675In versions prior to 2.0.5, reverse lookups (i.e. using
676.Fn getpwuid )
677would not have overrides applied, which is to say that it
678was possible for
679.Fn getpwuid
680to return a login name that
681.Fn getpwnam
682would not recognize.
683This has been fixed: overrides specified
684in
685.Pa /etc/master.passwd
686now apply to all
687.Xr getpwent 3
688functions.
689.It
690Prior to
691.Fx 2.0.5 ,
692netgroup overrides did not work at
693all, largely because
694.Tn FreeBSD
695did not have support for reading
696netgroups through NIS.
697Again, this has been fixed, and
698netgroups can be specified just as in
699.Tn SunOS
700and similar NIS-capable
701systems.
702.It
703.Tn FreeBSD
704now has NIS server capabilities and supports the use
705of
706.Pa master.passwd
707NIS maps in addition to the standard Sixth Edition format
708.Pa passwd
709maps.
710This means that you can specify change, expiration and class
711information through NIS, provided you use a
712.Tn FreeBSD
713system as
714the NIS server.
715.El
716.Sh FILES
717.Bl -tag -width /etc/master.passwd -compact
718.It Pa /etc/passwd
719.Tn ASCII
720password file, with passwords removed
721.It Pa /etc/pwd.db
722.Xr db 3 -format
723password database, with passwords removed
724.It Pa /etc/master.passwd
725.Tn ASCII
726password file, with passwords intact
727.It Pa /etc/spwd.db
728.Xr db 3 -format
729password database, with passwords intact
730.El
731.Sh SEE ALSO
732.Xr chpass 1 ,
733.Xr login 1 ,
734.Xr passwd 1 ,
735.Xr getpwent 3 ,
736.Xr login_getclass 3 ,
737.Xr yp 4 ,
738.Xr login.conf 5 ,
739.Xr adduser 8 ,
740.Xr pw 8 ,
741.Xr pwd_mkdb 8 ,
742.Xr vipw 8
743.Sh BUGS
744User information should (and eventually will) be stored elsewhere.
745.Pp
746The YP/NIS password database makes encrypted passwords visible to
747ordinary users, thus making password cracking easier unless you use
748shadow passwords with the
749.Pa master.passwd
750maps and
751.Tn FreeBSD Ns 's
752.Xr ypserv 8
753server.
754.Pp
755Unless you're using
756.Tn FreeBSD Ns 's
757.Xr ypserv 8 ,
758which supports the use of
759.Pa master.passwd
760type maps,
761the YP/NIS password database will be in old-style (Sixth Edition) format,
762which means that site-wide values for user login class, password
763expiration date, and other fields present in the current format
764will not be available when a
765.Tn FreeBSD
766system is used as a client with
767a standard NIS server.
768.Sh COMPATIBILITY
769The password file format has changed since
770.Bx 4.3 .
771The following awk script can be used to convert your old-style password
772file into a new style password file.
773The additional fields
774.Dq class ,
775.Dq change
776and
777.Dq expire
778are added, but are turned off by default.
779These fields can then be set using
780.Xr vipw 8
781or
782.Xr pw 8 .
783.Bd -literal -offset indent
784BEGIN { FS = ":"}
785{ print $1 ":" $2 ":" $3 ":" $4 "::0:0:" $5 ":" $6 ":" $7 }
786.Ed
787.Sh HISTORY
788A
789.Nm
790file format appeared in
791.At v6 .
792The YP/NIS functionality is modeled after
793.Tn SunOS
794and first appeared in
795.Fx 1.1
796The override capability is new in
797.Fx 2.0 .
798The override capability was updated to properly support netgroups
799in
800.Fx 2.0.5 .
801Support for comments first appeared in
802.Fx 3.0 .
803