2024年3月25日发(作者:)
linux讲义_用户和组管理命令练习
用户和组管理
基本用户环境
主目录: 用户登录后所在的目录,名称与用户名相同,在
/etc/passwd 文件的最后一个域中指定。/etc/skel: 其中的目录及文件
在新建用户时自动拷贝到用户主目录下。 几个重要文件
用户定义文件: /etc/passwd 组定义文件: /etc/group 口令文件:
/etc/shadow
一、用户和组文件
1. 用户账号文件——passwd
passwd 文件用于定义系统的用户账号,该文件位于“/etc ”目
录下。由于所有用户都对 passwd 有读权限,所以该文件中只定义用
户账号,而不保存口令。
passwd 文件中每行定义一个用户账号,一行中又划分为多个字段
定义用户账号的不同属性,各字段间用“:”分隔。passwd 文件的各
字段如表6-1所示。
表6-1 passwd 文件按字段划分 account password
UID GID GECOS directory shell root x 0 0 root /root /bin/bash
bin
x
1
bin
/bin
/sbin/nologin
passwd 文件中各字段的含义如表6-2所示,其中少数字段的内容
是可以为空的,但仍需使用“:”进行占位来表示该字段。
字段 命 名
account 用户账号名称,用户登录时所使用的用户名
password 用户口令,出于安全性考虑,现在已经不使用该字段保
存口令,而用字母“x ”
来填充该字段,真正的的密码保存在shadow 文件中 UID 用户号,
惟一表示某用户的数宇
GID 用户所属的私有组号,该数字对应group 文件中的GID
GECOS 可选的用户信息说明字段,通常用于保存用户全名的信息
directory 用户的宿主目录,用户成功登录后的默认目录 shell
用户所使用的shell ,如该字段为空则使用“/bin/sh ”
2. 用户口令文件——shadow
shadow 文件位于“/etc ”目录中,用于存放用户口令等重要信
息,所以该文件只有root 用户可以读取。
与passwd 文件类似,shadow 文件中每行定义一个用户的信息,
行中的各字段用“:”
#11/etc /passwd
-rw-r —r-- 1 root root 1359 May 23 16:09 /etc/passwd
//使用head 命令查看passwd 文件的前10行 #head
/etc/passwd
root:x:0:0:root:/root:/bin/bash
分隔。为了进一步提高安全性,shadow文件中保存的是已加密
的口令。可以使用#head /etc/shadow命令查看前10行的内容。
shadow文件的定义:
Username:The name the user types when logging into the
system. This allows the login
appli-cationto retrieve the user's password (and related
information).
Encrypted password:The 13 to 24 character password. The
password is encrypted using either the crypt library function, or
the md5 hash algorithm. In this field, values other than a
validly-formatted encrypted or hashed password are used to
control user logins and to show the password status. For example,
if the value is ! or * the account is locked, and the user is not


发布评论