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