配置文件——/etc/shadow

来源:互联网 发布:淘宝模特拍照价格 编辑:程序博客网 时间:2024/05/17 09:19
/etc/shadow配置文件
[linux@localhost ~]$ man 5 shadow
部分信息如下:
NAME
shadow - encrypted password file
DESCRIPTION
shadow contains the encrypted password information for user’s accounts and optional the password aging information. Included is:
· login name账户名
· encrypted password密文
· days since Jan 1, 1970 that password was last changed更改密码的时间
· days before password may be changed两次更改密码之间,至少需要间隔的天数
· days after which password must be changed密码的有效期限
· days before password is to expire that user is warned密码失效前的警告
· days after password expires that account is disabled账户注销时间
· days since Jan 1, 1970 that account is disabled帐号的使用期限
· a reserved field系统保留
The password field must be filled. The encrypted password consists of 13 to 24 characters from the 64 characters alphabet a thru z, A thru Z, 0 thru 9, \. and /.

Optionally it can start with a "$" character. This means the encrypted password was generated using another (not DES) algorithm. For example if it starts with "$1$" it means the MD5-based algorithm was used.
密文以$1$开头的是用MD5加密的,以$开头的密文不是用DES加密的。

If the password field contains some string that is not valid有效的 result , for instance ! or *, the user will not be
able to use a unix password to log in.

The date of the last password change is given as the number of days since Jan 1, 1970. The password may not be changed again until the proper number of days have passed, and must be changed after the maximum number of days. If the minimum number of days required is greater than the maximum number of day allowed, this password may not be changed by the user.

An account is considered to be inactive不活动 and is disabled if the password is not changed within the specified number of days after the password expires终止. An account will also be disabled on the specified day regardless不顾 of other password expiration终结 information.

[root@localhost ~]# cat /etc/shadow
部分信息:
root:$1$WX42FhLL$Eqdf4.8qYBtS0FPloCDZV/:15264:0:99999:7:::
bin:*:15264:0:99999:7:::
sabayon:!!:15264:0:99999:7:::
linux:$1$EjZjZrQT$VJrAce4g5baZiNoxqwE2H1:15263:0:99999:7:::
在shadow配置文件中,每条记录都有八个字段,每个字段之间利用冒号(:)进行分割。
  第一个字段:账户名。
  第二个字段:密文。用MD5或DES加密的密文。
  第三个字段:表示密码最后修改的时间。系统管理员或者用户可以更改密码,然后操作系统会记录最后更改的时间。不过这里记录的时间读起来比较困难,它是以天数为单位的。是1970年1月1日到更改密码时间的天数。
  第四个字段:密码两次更改之间,至少需要间隔的日数。有时候,密码过于频繁更改,对于应用系统的部署会有比较大的影响。如系统管理员在Linux操作系统上部署了文件共享服务。每个用户或者每个部门通过各自的帐户名与密码来访问这个文件服务器。此时,往往需要对这些用户的密码更改进行限制,如在一年之内不允许他们更改密码。因为如果更改密码的话,就需要在每个客户端上也进行相应的调整,这会增加维护的工作量。如果这个字段的值为0,则表示这个时间间隔的天数没有强制限制。
  第五个字段:密码的有效期限。这个字段表示密码更改后,距离下次一定要更改口令的天数。有时候系统管理员为了安全考虑,会给密码设置一个有效期限。当这个期限到后,就会提示用户更改密码。特别是当Linux服务器暴露在互联网上时,频繁更改密码确实是提高其安全性的一个重要手段。如果逾期不进行更改的话,就会受到警告,最后这个帐户可能就会被注销。如果这个字段的值为99999的话,就表示没有密码有效期的限制,用户可以永远是用这个密码。不过这是一个非常危险的做法,系统管理员还是需要慎用。
  第六个字段:密码失效前的警告。一般是在密码失效7天之前就开始警告用户,需要更改密码。而不是等到密码失效了,用户不能够利用原有帐户登陆了,才知道自己的密码失效。这个字段就是用来设置当离下次密码必须更改日期前多少天时,就开始警告用户需要更改密码。如果不需要警告信息的话,则这里显示的是空白。注意这根上面的有所区别,没有警告是以空白表示的,而不是以99999来表示。
  第七个字段:账户注销时间。如果用户不听系统的警告,在逾期后仍然没有及时更改密码,那么为了安全起见,系统可能会把这个帐户注销。要实现这个限制的话,就需要在这个字段中进行设置。这个字段就表示超过口令必须更改的日期多少天后,系统会自动将这个帐户注销掉。如这里设置为5天,而密码到期的时间为2009年6月1日。如果用户在5天之内没有更改密码,则到6月6日的时候,系统就会自动的将这个帐户注销,不允许用户登录。
  第八个字段:帐号的使用期限。不仅密码具有使用期限,而且帐号也具有使用期限。有些帐号的使用期限控制非常有用。当过了这个有效期之后,系统就会锁住这些帐户。故通过这个管理机制,就可以最大限度的保障这些帐号的安全。即系统管理员不用再费心的去管理这些帐号,其过期后会自动注销。如果这字段为空白的话,就表示没有账号使用期限的限制,其会永久生效。注意通常情况下不要为root帐户设置这方面的限制。否则的话,后果会不堪设想。
  第九个字段:这最后一个字段到现在为止还是一个预留字段,以待后续操作系统升级时使用。

通常情况下,前面三个字段最好不要更改。后面的内容可以根据需要来调整。不过在账号有效期限这个字段中,不要为root帐户设置账号期限。因为root账号主要用来做管理用。

密文介绍:如果密码字符串为*,表示系统用户不能被登入,!表示用户名被禁用,如果密码字符串为空,表示没有密码,通过passwd -d 用户名 可以清空一个用户的口令,该命令只有超级用户才能使用。
密文是由操作系统写入shadow文件中的,超级用户可以通过pwconv命令将密文从passwd配置文件中写入shadow文件中,可以同过pwunconv命令将shadow文件中的密文回写入passwd配置文件中。在商用版linux中都不提供这两个命令。

用户登录时用户名是在/etc/passwd配置文件中验证的,密码是在/etc/shadow配置文件中验证的。