1./etc/passwd
Passwd文件由许多条记录组成,每条记录占一行,记录了一个用户帐号的所有信息。每条记录由7个字段组成,字段间用冒号“:”隔开,其格式如下:
username:password:User ID:Group ID:comment:home directory:shell
字段含义:
username 用户名
它唯一地标识了一个用户帐号,用户在登录时使用的就是它。
password 该帐号的口令
passwd文件中存放的密码是经过加密处理的。Linux的加密算法很严密,其中的口令几乎是不可能被破解的。盗用帐号的人一般都借助专门的黑客程 序,构造出无数个密码,然后使用同样的加密算法将其加密,再和本字段进行比较,如果相同的话,就代表构造出的口令是正确的。因此,建议不要使用生日、常用 单词等作为口令,它们在黑客程序面前几乎是不堪一击的。特别是对那些直接连入较大网络的系统来说,系统安全性显得尤为重要。
User ID 用户识别码,简称UID。
Linux系统内部使用UID来标识用户,而不是用户名。UID是一个整数,用户的UID互不相同。
Group ID 用户组识别码,简称GID。
不同的用户可以属于同一个用户组,享有该用户组共有的权限。与UID类似,GID唯一地标识了一个用户组。
comment 这是给用户帐号做的注解
它一般是用户真实姓名、电话号码、住址等,当然也可以是空的。
home directory 主目录
这个目录属于该帐号,当用户登录后,它就会被置于此目录中,就像回到家一样。一般来说,root帐号的主目录是/root,其他帐号的家目录都在/home目录下,并且和用户名同名。
login command 用户登录后执行的命令
一般来说,这个命令将启动一个shell程序。例如,用bbs帐号登录后,会直接进入bbs系统,这是因为bbs帐号的login command指向的是bbs程序,等系统登录到bbs时就自动运行这些命令。
系统帐号
系统中还有一些默认的帐号,如daemon、bin等。这些帐号有着特殊的用途,一般用于进行系统管理。这些帐号的口令大部分用(x)号表示,代表它们不能在登录时使用。
2./etc/shadow
/etc/passwd文件是任何人都可以读的,那么那些心有所图的人就可以利用这个文件,使用各种各样的工具按照Linux密码加密的方法把用户甚至root的密码试出来,这样整个系统就会被他所控制,严重危害系统的安 全和用户数据的保密性。为了增强系统的安全性,Linux系统还可以为用户提供MD5和Shadow安全密码服务。如果在安装 Linux 时在相关配置的选项上选中了MD5和Shadow服务,那么将看到的/etc/passwd文件里的passwd项上无论是什么用户,都是一个“x”,这就表示这些用户都登录不了;系统其实是把真正的密码数据放在了/etc/shadow文件里。
/etc/shadow文件只能以具有管理员身份的用户(root或者UID=1的用户)来浏览,格式如下:
username:password:lastchg:min:max:warn:inactive:expire:flag
The fields are defined as follows:
username The user's login name (UID).
password An encrypted password for the user generated
by crypt(3C), a lock string to indicate that
the login is not accessible, or no string,
which shows that there is no password for
the login.
The lock string is defined as *LK* in the
first four characters of the password field.
lastchg The number of days between January 1, 1970,
and the date that the password was last
modified. The lastchg value is a decimal
number, as interpreted by atol(3C).
min The minimum number of days required between
password changes. This field must be set to
0 or above to enable password aging.
max The maximum number of days the password is
valid.
warn The number of days before password expires
that the user is warned.
inactive The number of days of inactivity allowed for
that user. This is counted on a per-machine
basis; the information about the last login
is taken from the machine's lastlog file.
expire An absolute date expressed as the number of
days since the Unix Epoch (January 1, 1970).
When this number is reached the login can no
longer be used. For example, an expire value
of 13514 specifies a login expiration of
January 1, 2007.
flag Failed login count in low order four bits;
remainder reserved for future use, set to
zero.
有关命令
pwconv
根据/etc/passwd文件生成/etc/shadow。它把所有口令从/etc/passwd移到/etc/shadow中。
pwunconv
将/etc/shadow中的信息尽可能地恢复到/etc/passwd。