Go to main content

手册页部分 1:用户命令

退出打印视图

更新时间: 2022年7月27日 星期三
 
 

passwd (1)

名称

passwd - 更改登录口令和口令属性

用法概要

passwd [-r files | -r ldap | -r nis] [name]
passwd [-r files] [-egh] [name]
passwd [-r files] -s [-a]
passwd [-r files] -s [name]
passwd [-r files] [-d | -l | -u | -N | -p hash] [-f] [-n min]
     [-w warn] [-x max] name
passwd -r ldap [-egh] [name]
passwd [-r ldap ] -s [-a]
passwd [-r ldap ] -s [name]
passwd -r ldap [-d | -l | -u | -N | -p hash] [-f] [-n min]
     [-w warn] [-x max] name
passwd -r nis [-egh] [name]

描述

passwd 命令可以更改口令,或者列出与用户的登录 name 关联的口令属性。Additionally, authorized users can use passwd to install or change passwords and attributes associated with any login name, as described in the Authorized User Options section below.

When used by a user to change their own password, passwd prompts the user for their old password, if any.然后,它会两次提示用户输入新口令。The passwd command does not prompt for the old password when used by a user who is authorized to change other users passwords.

If LDAP is one of the configured nameservices, an authorized user on any LDAP client system can change any password without being prompted for the old LDAP password.

输入旧口令时,passwd 会检查并确定旧口令是否已到期。如果 aging 不足,passwd 将终止。For additional information, see the shadow(5) man page.

如果生命期已满,则会执行检查,以确保新口令符合构造要求。在第二次输入新口令时,系统会比较新口令的两个副本。如果两个副本不同,将再次提示输入新口令(此循环最多重复执行两次)。

构造的口令必须符合以下要求:

  • Each password must have at least PASSLENGTH characters, where PASSLENGTH is defined in /etc/default/passwd and is set to 8 by default.PASSLENGTH may be set to more than eight characters as long as policy.conf(5) has not been configured to use an algorithm that only supports eight characters, such as the legacy crypt_unix(7).

  • 每个口令都必须满足 /etc/default/passwd 中指定的已配置复杂性约束。

  • 每个口令都不得是 /etc/default/passwd 中指定的已配置字典的成员。

  • 对于支持口令历史记录检查的名称服务中的帐户,如果定义了先前的口令历史记录,则新口令不得包含在先前的口令历史记录中。

在缺省情况下,即使有权更改其他用户口令的用户也必须遵循已配置的口令策略。Users with the solaris.passwd.nocheck authorization may bypass these checks.For more information, see pam_authtok_check(7).

If all requirements are met, by default, the passwd command consults nsswitch.conf(5) to determine in which repositories to perform password update.The sources (repositories) associated with the passwd entry are updated.然而,支持的口令更新配置有限,并且应遵循以下规则:

  • passwd 行必须具有一个、两个或三个条目。

  • 第一个 passwd 条目应为 files。

  • 在口令更新期间将忽略并跳过除 files、NIS 和 LDAP 以外的 passwd 条目。It is necessary to use a source-specific tool to update passwords in such other databases.

拥有口令表的网络管理员可以更改任何口令属性。为更新 LDAP 影子信息而配置的管理员也可以更改任何口令属性。有关更多信息,请参见 ldapclient(8) 手册页。

当用户将口令存储在一个名称服务和一个本地 files 条目中时,passwd 命令会同时更新两者。名称服务和本地 files 条目可以包含不同的口令。使用 passwd –r 可更改特定口令系统信息库。

正常情况下,输入无参数的 passwd 可以更改当前用户的口令。When a user logs in and then invokes su(8) to assume a role or become another user, passwd changes the original user's password, not the password of the role or the new user.

安全性

passwd 使用 pam(3PAM) 更改口令。它通过服务名称 passwd 调用 PAM,并使用服务模块类型 auth 进行验证,使用口令更改口令。

锁定帐户(–l 选项)后,该帐户便不允许用于任何登录或延迟执行(例如 at(1), batch(1)cron(8))。–N 选项可用于禁止基于口令登录,同时继续允许延迟执行或使用非 UNIX 验证方法登录。

从来没有口令的已锁定帐户不能将其状态直接更改为活动 password。请参见 –d 选项。对于锁定之前有口令的锁定帐户,更改其口令时,无需解锁帐户即可更改口令。请参见用于解锁帐户的 –u 选项。授权管理员可以激活处于尚未激活状态的帐户,具体方法是为该帐户提供口令或运行 passwd –N,但管理员只能出于非 UNIX 验证或延迟执行的目的激活该帐户。

帐户在不活动之后会被锁定。要解锁此类帐户,请使用 –u–f 选项。使用 –u 无法更改口令;使用 –f 可以强制更改口令。

选项

支持以下选项:

–a

显示所有条目的口令属性。仅与 –s 选项结合使用。不可提供 name。For the files and ldap repositories, this is restricted to users with the solaris.account.setpolicy authorization.

–e

更改登录 shell。选择 shell 时会受到 getusershell(3C) 的要求的限制。If the user currently has a shell that is not allowed by getusershell(), usermod -s must be used to change it.

–g

更改 gecos(指针)信息。

–h

This option formerly changed the home directory, but now just prints a message to use usermod -d instead.

–r

指定向其应用操作的系统信息库。支持的系统信息库包括 filesldapnis

–s name

显示登录 name 的口令属性。For the files and ldap repositories, this only works for users with the solaris.account.setpolicy authorization.它完全不适用于 nis 系统信息库,因为此系统信息库不支持口令生命期。

此选项(也只有此选项)的输出为 "Committed"(已确定)并且可解析。将来有可能添加新代码,因此,解析此命令的代码必须能够灵活应对未知代码。所有现有代码均为两个字符,但将来未必始终如此。

其显示格式为:

name status mm/dd/yy min max warn

或者(如果没有口令生命期信息):

name status

其中

name

用户的登录 ID。

status

name 的口令状态。

status 字段可以采用以下值:

AL

由于验证失败次数达到了配置的最大允许次数而自动锁定了帐户。请参见 policy.conf(5)user_attr(5) 以及“安全”部分。

LK

帐户已锁定。运行了 passwd –l,或者由于验证失败次数达到了配置的最大允许次数而自动锁定了帐户。请参见 policy.conf(5)user_attr(5) 以及“安全性”部分。

NL

该帐户是非 UNIX 验证帐户。passwd –N 已运行。See “Security”.系统或每用户策略为 LOCK_AFTER_RETRIES=YES 时,不会自动锁定处于此状态的帐户。

NP

This account has no password and is therefore open without authentication. passwd -d was run.

PS

帐户可能有一个有效口令。

UN

口令字段中的数据未知。它不是一个可识别的散列口令或上述各项中的任何一个。请参见 crypt(3C) 了解有效的口令散列。

UP

管理员尚未激活帐户,因此无法使用。See Security.

mm/dd/yy

上次更改 name 的口令的日期。All password aging dates are determined using Coordinated Universal Time (UTC) and therefore can differ by as much as a day in other time zones.

min

name 更改口令需要间隔的最少天数。在 /etc/default/passwd 中有 MINWEEKS,并且设置为 NULL

max

name 口令的最大有效天数。在 /etc/default/passwd 中有 MAXWEEKS,并且设置为 NULL

warn

口令到期之前相对于 max 的天数,达到此天数后 name 将收到警告消息。

The default password aging policy can be specified in either days or in weeks.当为 MAXWEEKSMINWEEKS 指定了缺省值时,将使用天作为单位来更新 shadow(5) 数据库。同时为给定 MIN/MAX/WARN 变量设置 WEEKSDAYS 变体是错误的。The MIN and WARN policies are only active if a MAX policy is also set.

Authorized User Options

管理员需要获得 "User Security"(用户安全)配置文件才能锁定和解锁现有帐户。此配置文件也可以提供激活新建帐户、设置口令生命期选项和查看口令属性的功能。下表列出了执行各种操作所需的授权。

只有授权用户才能使用以下选项:

–d

删除 name 的口令并解锁帐户。登录 name 不会收到输入口令的提示。It is only applicable to the files and ldap repositories.

If the login(1) option PASSREQ=YES is configured, the account is not able to login.PASSREQ=YES 为缺省设置。

–f

通过使 name 的口令到期,强制用户在下一次登录时更改口令。解锁由于不活动而遭到锁定的帐户时,此选项十分有用。

–l

锁定 name 的帐户,除非已经锁定。请参见用于解锁帐户的 –u 选项。仅标记为非 UNIX 验证或延迟执行的帐户可以锁定并会在解锁时返回同一状态。

–N

使 name 的口令条目成为一个无法用于通过 UNIX 验证进行登录的值,但不会锁定该帐户。请参见用于删除此值的 –d 选项或者用于锁定帐户的 –l 选项。

–p hash

指定要放置在影子口令字段中的确切字符串值。Strings may be generated using the pwhash(1) command.用户必须同时具有 solaris.passwd.assignsolaris.passwd.nocheck 授权。它用于为口令散列更新编写脚本。Its use is generally discouraged, as the hashed password is visible through ps(1) and other proc(5) tools while the command runs.

–n min

设置 name 的最小值字段。min 字段包含更改 name 的口令需间隔的最少天数。如果 min 大于 max,用户将无法更改口令。此选项应始终与 –x 选项配合使用,除非 max 设置为 -1(禁用生命期)。在这种情况下,min 无需设置。

–u

解锁 name 条目的已锁定口令。解锁由于登录尝试失败而遭到锁定或者通过管理方式(使用 –l 选项)锁定的帐户时,–u 选项十分有用。标记为非 UNIX 验证帐户 (passwd –N) 的帐户会返回解锁时的状态。

–w warn

name 设置警告字段。warn 字段包含口令到期之前的天数,达到此天数时用户将收到警告消息。如果禁用口令生命期,此选项无效。

–x max

设置 name 的最大值字段。max 字段包含 name 的口令的有效天数。如果 max 设置为 -1,会立即禁用 name 的生命期。

The authorizations, as defined in user_attr(5), which are required to perform restricted operations are as follows:

Option
Operation
Authorization
–d
Delete password
solaris.passwd.assign
–N
Set nologin
solaris.passwd.assign
 
Change any password
solaris.passwd.assign
 
Bypass complexity checks
solaris.passwd.nocheck
–l
Lock account
solaris.account.setpolicy
–u
Unlock account
solaris.account.setpolicy
–n
Set min field for name
solaris.account.setpolicy
–w
Set warn field for name
solaris.account.setpolicy
–f
Force password expiration
solaris.account.setpolicy
–s
Display password attributes
solaris.account.setpolicy
–a
Display password attributes for all entries
solaris.account.setpolicy
–e
Change login shell
solaris.user.manage
–g
Change gecos information
solaris.user.manage
–h
Change home directory
solaris.user.manage
 
Set a password for the first time for a newly created account
solaris.account.activate

操作数

支持下列操作数:

name

User login name.

环境变量

如果任一 LC_* 变量(即 LC_CTYPE、LC_MESSAGES、LC_TIME、LC_COLLATE、LC_NUMERIC 和 LC_MONETARY(请参见 environ(7)))未在此环境中进行设置,则 passwd 针对每个对应语言环境类别的操作行为将由 LANG 环境变量的值确定。如果设置了 LC_ALL,则会使用其内容覆盖 LANG 和其他 LC_* 变量。如果以上变量都未在此环境中进行设置,则 C(美国样式)语言环境将确定 passwd 的行为。

LC_CTYPE

确定 passwd 如何处理字符。When LC_CTYPE is set to a valid value, passwd can display and handle text and filenames containing valid characters for that locale. passwd can display and handle Extended UNIX Code (EUC) characters where any individual character can be 1, 2, or 3 bytes wide. passwd can also handle EUC characters of 1, 2, or more column widths.在 C 语言环境中,只有 ISO 8859-1 中的字符有效。

LC_MESSAGES

确定如何显示诊断和信息性消息。这包括消息的语言和风格,以及肯定性和否定性响应的正确形式。在 C 语言环境中,消息将以程序自身中的缺省格式显示(大多数情况下,为美式英文)。

退出状态

passwd 命令退出时会返回以下值之一:

0

成功。

1

权限被拒绝。

2

无效的选项组合。

3

意外失败。口令文件未更改。

4

意外失败。口令文件缺失。

5

口令文件正忙。请稍后重试。

6

无效的选项参数。

7

生命期选项已禁用。

8

无内存。

9

系统错误。

10

帐户已过期。

11

Password information unchanged.

文件

/etc/default/passwd

/etc/default/passwd 文件已过时。However, you can use the svc:/system/account-policy:default service to set the corresponding SMF properties.

下表列出了 /etc/default/passwd 中的属性与 SMF 属性之间的映射:

Property in /etc/default/passwd
Corresponding SMF Property
DICTIONDBDIR
password/dictionary/db_dir
DICTIONLIST
password/dictionary/word_list
DICTIONMINWORDLENGTH
password/dictionary/min_word_length
HISTORY
password/history
MAXREPEATS
password/complexity/max_repeats
MAXDAYS
password/aging_defaults/max_days
MAXWEEKS
password/complexity/max_days
MINALPHA
password/complexity/min_alpha
MINDIFF
password/complexity/min_diff
MINDIGIT
password/complexity/min_digit
MINLOWER
password/complexity/min_lower
MINNONALPHA
password/complexity/min_nonalpha
MINDAYS
MINWEEKS
password/complexity/min_days
MINSPECIAL
password/complexity/min_special
MINUPPER
password/complexity/min_upper
NAMECHECK
password/complexity/namecheck
PASSLENGTH
password/complexity/passlength
WARNDAYS
password/aging_defaults/warn_days
WARNWEEKS
password/complexity/warn_days
WHITESPACE
password/complexity/whitespace

有关管理 SMF 属性的信息,请参见 account-policy(8S) 手册页。

/etc/default/passwd 文件中的属性的描述如下:

DICTIONDBDIR

生成的字典数据库所在的目录。缺省值为 /var/passwd

如果未指定 DICTIONLISTDICTIONDBDIR,系统将不会执行字典检查。

DICTIONLIST

DICTIONLIST 可以包含以逗号分隔的字典文件列表,例如 DICTIONLIST=file1file2file3。每个字典文件都包含多行,每行由一个词和一个换行符组成。您必须指定全路径名。来自这些文件的词会合并为一个数据库,用于确定口令是否基于字典中的词。

可以在 DICTIONLIST 中列出拼写检查字典(类似于 /usr/share/lib/dict/words),但需要预先进行处理。请参见下文的 DICTIONMINWORDLENGTH 了解更简便的方法。

如果未指定 DICTIONLISTDICTIONDBDIR,系统将不会执行字典检查。

要预先构建字典数据库,请参见 mkpwdict(8)

DICTIONMINWORDLENGTH

DICTIONMINWORDLENGTH 可以包含一个数字,用于指定 DICTIONLIST 中源文件的最小词长。小于指定长度的词将在口令字典中省略。

允许的最小值为 2 [个字母];缺省值为 3 [个字母]。

HISTORY

为用户所保存的先前口令历史记录的最大数量。将 HISTORY 值设为零 (0) 或者删除标志都会导致下一次任何用户更改口令时放弃所有用户的先前口令历史记录。缺省情况下不会定义 HISTORY 标志。The maximum value is 26.Currently, this functionality is enforced only for user accounts defined in the files name service (local passwd(5)/shadow(5)).

MAXREPEATS

允许的连续重复字符的最大个数。如果未设置 MAXREPEATS,或者将其设为零 (0),则缺省情况下不会进行检查。

MAXDAYS

口令的最长有效期(以天为单位)。

MAXWEEKS

口令的最长有效期(以周为单位)。

MINALPHA

必须包含的最少字母字符个数。如果未设置 MINALPHA,则缺省值为 2

MINDIFF

旧口令和新口令之间必须具有的最小差异。如果未设置 MINDIFF,则缺省值为 3

MINDIGIT

必须包含的最少数字个数。如果未设置 MINDIGIT,或者将其设为零 (0),则缺省情况下不会进行检查。如果同时指定了 MINNONALPHA,将无法指定 MINDIGIT

MINLOWER

Minimum number of lowercase letters required.如果未设置,或者将其设为零 (0),则缺省情况下不会进行检查。

MINNONALPHA

必须包含的最少非字母字符(包括数字和特殊字符)个数。If MINNONALPHA is not set, the default is 1.如果同时指定了 MINDIGITMINSPECIAL,则将无法指定 MINNONALPHA

MINDAYS

更改口令的最短间隔时间(以天为单位)。

MINWEEKS

更改口令的最短间隔时间(以周为单位)。

MINSPECIAL

必须包含的最少特殊字符(非字母和数字)个数。如果未设置 MINSPECIAL,或者将其设为零 (0),则缺省情况下不会进行检查。如果同时指定了 MINNONALPHA,则将无法指定 MINSPECIAL

MINUPPER

Minimum number of uppercase letters required.如果未设置 MINUPPER,或者将其设为零 (0),则缺省情况下不会进行检查。

NAMECHECK

启用/禁用登录名检查。缺省设置为执行登录名检查。使用 no 值(不区分大小写)会禁用此功能。

PASSLENGTH

口令的最小长度(以字符为单位)。

WARNDAYS

发出口令即将到期警告前的时间长度(以天为单位)。

WARNWEEKS

发出口令即将到期警告前的时间长度(以周为单位)。

WHITESPACE

确定口令中是否允许使用空格字符。有效值为 YESNO。如果未设置 WHITESPACE,或者将其设为 YES,则允许使用空格字符。

/etc/oshadow

passwdpwconv 用来更新实际影子文件的临时文件。

/etc/passwd

口令文件。

/etc/shadow

影子口令文件。

/etc/shells

Shell 数据库。

属性

有关下列属性的说明,请参见 attributes(7)

属性类型
属性值
可用性
system/core-os
CSI
Enabled(已启用)
接口稳定性
请参见下文。

用户可读的输出是 "Uncommitted"(未确定)。The options are Committed, as is the parsable output of the –s option.

另请参见

at(1), batch(1), finger(1), login(1), pwhash(1), crypt(3C), getpwnam(3C), getspnam(3C), getusershell(3C), pam(3PAM), crypt.conf(5), loginlog(5), nsswitch.conf(5), pam.conf(5), passwd(5), policy.conf(5), shadow(5), shells(5), user_attr(5), attributes(7), crypt_unix(7), environ(7), pam_authtok_check(7), pam_authtok_get(7), pam_authtok_store(7), pam_dhkeys(7), pam_ldap(7), pam_unix_account(7), pam_unix_auth(7), pam_unix_session(7), rbac(7), cron(8), eeprom(8), id(8), ldapclient(8), mkpwdict(8), pwconv(8), su(8), useradd(8), userdel(8), usermod(8), account-policy(8S)

Managing User Accounts and User Environments in Oracle Solaris 11.4

附注

yppasswd 命令是 passwd 的包装器。建议不要使用 yppasswd,而是使用 passwd –r repository_name

filesldap 系统信息库中更改口令将清除失败登录次数。

更改口令会重新激活由于不活动达到一定时间而被禁用的帐户。

输入终端处理可能会解释某些键序列而不将其传递给 passwd 命令。

无口令帐户(状态代码为 NP)可能无法登录。请参见 login(1) PASSREQ 选项。

All password hash algorithms provided with Oracle Solaris 11.4, except for crypt_unix(7), have a maximum password length of 255.See crypt.conf(5) and account-policy(8S) for information on configuring the algorithm to use.

unlock_after 用户属性仅适用于因超出失败登录次数而锁定的帐户。

History

The AL status code; the properties MAXDAYS, MINDAYS, and WARNDAYS; and the use of the account-policy(8S) SMF service to store the property values were added to Oracle Solaris in Solaris 11.4.0.

The –p option was added to Oracle Solaris in Solaris 11.3.4.

The DICTIONMINWORDLENGTH property was added to Oracle Solaris in Solaris 11.1.17 and a Solaris 10 patch.

Support for NIS+, including the –D option, and the nisplus repository argument for the –r option, was removed in Solaris 11.0.0.

Support for the –h option was removed in Solaris 11.0.0.

The –N and –u options; and the properties DICTIONDBDIR, DICTIONLIST, HISTORY, MAXREPEATS, MINALPHA, MINDIFF, MINDIGIT, MINLOWER, MINNONALPHA, MINSPECIAL, MINUPPER, NAMECHECK, and WHITESPACE; were added to Oracle Solaris in Solaris 10 3/05.

Support for password encryption algorithms beyond the traditional UNIX crypt(3C), via the crypt.conf(5) configuration, was added to Solaris in Solaris 9 12/02 (Update 2).

Support for LDAP, including the ldap repository argument for the –r option, was added in Solaris 8.

The options –r (with the files, nis, and nisplus repositories), –e, –g, –h, and –D were added to Solaris in Solaris 2.5.

The options –d, –f, –l, –s, and –w, and support for the /etc/default/passwd file, with the properties MAXWEEKS, MINWEEKS, PASSLENGTH, and WARNWEEKS, were added to Solaris in Solaris 2.0.

The options –a, –n, and –x were added in SunOS 4.1 and have been present in all releases of Solaris.

The passwd command has been included in all releases of SunOS and Solaris.