linux讲义用户和组管理命令练习

上传人:平*** 文档编号:14380132 上传时间:2017-11-01 格式:DOC 页数:14 大小:95.79KB
返回 下载 相关 举报
linux讲义用户和组管理命令练习_第1页
第1页 / 共14页
linux讲义用户和组管理命令练习_第2页
第2页 / 共14页
linux讲义用户和组管理命令练习_第3页
第3页 / 共14页
linux讲义用户和组管理命令练习_第4页
第4页 / 共14页
linux讲义用户和组管理命令练习_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《linux讲义用户和组管理命令练习》由会员分享,可在线阅读,更多相关《linux讲义用户和组管理命令练习(14页珍藏版)》请在金锄头文库上搜索。

1、 用户和组管理基本用户环境主目录: 用户登录后所在的目录 ,名称与用户名相同,在/etc/passwd文件的最后一个域中指定。/etc/skel: 其中的目录及文件在新建用户时自动拷贝到用户主目录下。几个重要文件用户定义文件: /etc/passwd组定义文件: /etc/group口令文件: /etc/shadow一、用户和组文件1. 用户账号文件passwdpasswd 文件用于定义系统的用户账号,该文件位于“ /etc”目录下。由于所有用户都对 passwd 有读权限,所以该文件中只定义用户账号,而不保存口令。passwd 文件中每行定义一个用户账号,一行中又划分为多个字段定义用户账号的

2、不同属性,各字段间用“:”分隔。passwd 文件的各字段如表 6-1 所示。表 61 passwd 文件按字段划分account password UID GID GECOS directory shellroot x 0 0 root /root /bin/bashbin x 1 0 bin /bin /sbin/nologinpasswd 文件中各字段的含义如表 6-2 所示,其中少数字段的内容是可以为空的,但仍需使用“:”进行占位来表示该字段。字段 命 名account 用户账号名称,用户登录时所使用的用户名 password 用户口令,出于安全性考虑,现在已经不使用该字段保存口令,而

3、用字母“x”来填充该字段,真正的的密码保存在 shadow 文件中 UID 用户号,惟一表示某用户的数宇 GID 用户所属的私有组号,该数字对应 group 文件中的 GIDGECOS 可选的用户信息说明字段,通常用于保存用户全名的信息directory 用户的宿主目录,用户成功登录后的默认目录shell 用户所使用的 shell,如该字段为空则使用“/bin/sh ”2. 用户口令文件shadowshadow 文件位于 “etc”目录中,用于存放用户口令等重要信息,所以该文件只有root 用户可以读取。与 passwd 文件类似,shadow 文件中每行定义一个用户的信息,行中的各字段用#1

4、1etcpasswd-rw-rr- 1 root root 1359 May 23 16:09 /etc/passwd/使用 head 命令查看 passwd 文件的前 10 行#head /etc/passwdroot: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 t

5、he login appli-cationto retrieve the users 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 pa

6、ssword 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 allowed to login. Date password last changed:The number of days since January 1, 1970 (also called the epoch)that the password was last changed. This

7、 information is used for the following password aging fields. Number of days before password can be changed:The minimum number of days that must pass before the password can be changed. Number of days before password change is required :The number of days that must pass before the password must be c

8、hanged. Number of days warning before password change:The number of days before password expiration during which the user is warned of the impending expiration. Number of days before the account is disabled :The number of days after a password expires before the account will be disabled. Date since

9、the account has been disabled:The date (stored as the number of days since the epoch) since the user account has been disabled. A reserved eld:A field that is ignored in Red HatLinux. shadow的例子:Here is an example line from /etc/shadow: juan:$1$.QKDPc5E$SWlkjRWexrXYgc98F.:11956:0:90:5:30:12197: This

10、line shows the following information for user juan: The password was last changed September 25, 2002 There is no minimum amount of time required before the password can be changed The password must be changed every 90 days The user will get a warning vedays before the password must be changed. The a

11、ccount will be disabled 30 days after the password expires if no login attempt is made The account will expire on May 24, 2003 For more information on the /etc/shadow le, type man 5 shadow. 3. 用户组帐号文件groupgroup文件位于“/etc”目录,用于存放用户的组账号信息,该文件的内容任何用户都可以读取。group文件中每行定义一个用户组的信息,各字段间用“:”分隔。group 文件中每个用户组的信

12、息由4个字段组成,如表6-3所示。表63 group文件的各字段group_name password GID user_listroot x 0 rootbin x 1 root,bin,daemondaemon x 2 root,bin,daemongroup文件中各字段所代表的含义如表 64所示。表64 group文件字段说明字段 说 明group_name 用户组的名称 password 用户组口令,由于安全性原因,已不使用该字段保存口令,用“x”占位GID 用户组标识号,该数字用于惟一表示一个用户组 user_list 属于该组的用户成员列表,列表中多个用户间用“,”分隔 4. 组口

13、令文件gshadowgshadow 文件用于定义组口令、组管理员等信息,该文件只有 root 用户可以读取。gshadow 文件中每行定义一个用户的信息,行中各段间用 “:“分隔。gshadow 文件中每个用户组的信息由四个字段组成,如表 65 所示。表 65 gshadow 中的各字段Group name Encrypted password Group administrators Group membersroot rootbin root,bin,daemongshadow 文件中各字段所代表的含义如表 66 所示。表 66 gshadow 文件字段说明字段 说 明Group name

14、 用户组名称,该字段与 group 文件中的组名称对应Encrypted password 用户组口令,该字段用于保存已加密的口令Group administrators 组的管理员帐号,管理员有权对该组添加删除帐号Group members 属于该组的用户成员列表,列表中多个用户间用“, ”分隔二、用户帐号维护命令1. useradd(adduser) 添加用户帐号命令格式:useradd 用户名功能描述:useadd 命令用于添加用尸账号。在使用 useradd 命令添加用尸账号后需使用 passwd 命令设置用户口令,才可以使用此账号进行登录,否则此账号被禁止登录。应用实例:/建立用户帐

15、号 user1#useradd user1/查看 passwd 文件中添加的用户帐号信息#tail 1 /etc/passwd /输出文件的最后一行#tail 1 /etc/shadow/为用户 user1 设置口令#passwd user1 在添加用户帐号时指定用户私有组命令格式:useradd g 组名 用户名功能描述:useradd -g 命令用于添加用户账号并设置该用户的私有组。如不指定“-g”参数,useradd 命令将自动建立与用户账号同名的组作为该账号的私有组。使用“-g”参数指定用户私有组有利于对用户进行分组管理。应用实例: 显示 useradd 命令的默认值useradd 命

16、令的默认值是指当使用 useadd 命令添加用户账号时,如未指定相应的参数则使用默认值设置。命令格式:useradd D功能描述:useradd D 命令用于显示或设置 useradd 命令使用的默认值。应用实例:相关文件:useradd 命令使用的默认值保存在文件“/etc/default/useradd ”中。 修改 useradd 命令的默认值命令格式:useradd D -g group -b base -s shell -f inactive -e expire功能描述:usemdd-D 命令指定适当的参数用于改变 useradd 命令所使用的默认值。应用实例:#useradd g root user1#tail 1 /etc/passwd#useradd DGROUP=100HOME=/homeINACTIVE=

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号