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