rhcsa第六次作业

1.linux中用户的类型

超级用户——用户名为root,它具有一切权限,只有进行系统维护(例如:建立用户等)或其他必要 情形下才用超级用户登录,以避免系统出现安全问题。
系统用户(伪用户)——是Linux系统正常工作所必需的用户。主要是为了满足相应的系统进程对文件属主的要求而建立的,例如:bin、daemon、adm、lp等用户。系统用户不能用来登录。
普通用户——是为了让使用者能够使用Linux系统资源而建立的,我们的大多数用户属于此类。
linux中用户组的类型

基本组(私有组):建立账户时,若没有指定账户所属的组,系统会建立一个和用户名相同的组,这 个组就是基本组。
附加组(公有组):可以容纳多个用户,组中的用户都具有组所拥有的权利。

  linux中存储用户信息的文件是哪个?且其中的字段是什么意思

(1 )用户账号文件 ——/etc/passwd
passwd 是一个文本文件,用于定义系统的用户账号,由于所有用户都对 passwd 有读权限,所以该文件
中只定义用户账号,而不保存口令。
[root@192 ~]# head -1 /etc/passwd
root:x:0:0:root:/root:/bin/bash

注意: 每行定义一个用户账号信息,每行由 7 个字段组成,字段之间用 “:” 分隔,其格式如下:

账号名称:密码:UID:GID:个人资料:主目录:Shell

账户名称用户登录时所用的名称
密码以前以加密形式保存密码的位置,现在密码保存在/etc/shadow、文件中,“x”代表密码占位符,同时说明密码受到shadow文件的保护
UID

用户标识,区分用户

超级用户UID--0

系统用户UID--1~999

普通用户UID-->=1000

GID用户所在基本组的标识,区分不同组
个人资料记录用户的个人信息等
主目录类似 Windows 的个人目录,通常是 /home/username ,这里 username 是用户名,用户执行 “cd ~ ” 命令时当前目录会切换到个人主目录。
 
shell用户登录激活后的shell,默认为Bash Shell

(2 )用户密码文件 ——/etc/shadow
[root@192 ~]# head -1 /etc/shadow
root:$6$GrqzJ9hOAJGHyjiY$4lv52Wmp.0.hH0Iep4C8oRc/DgmETwMZ0HDmp6XNYZMUHHgsnEFkA8IQ6wexyBkPSltwxBx9jPz2/11fOTBgd.::0:99999:7:::
注意: 每行定义了一个用户信息,行中各字段用 “:” 隔开 , 其格式如下:
登录名 : 加密口令 : 最后一次修改时间 : 最小时间间隔 : 最大时间间隔 : 警告时间 : 不活动时间 : 失效时间 : 标志
 

登录名登录名字
加密口令使用 SHA-512/SHA-256/MD5 算法加密后的密码( $id$ , id 为 1 表示 md5 , 5 表示sha256 , 6 为 sha512 ),若为空,表示该用户无需密码即可登录,若为 “*” 表示该账号不 能用于登录系统,若为 “ !! ” 表示该账号密码已被锁定
————————————————
版权声明:本文为CSDN博主「树窗」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_59180100/article/details/125895903
最后一次修改时间最近一次更改密码的日期 , 以距离 1970 年 1 月 1 日的天数表示
最小时间间隔密码在多少天内不能被修改。默认值为 0, 表示不限制
最大时间间隔密码在多少天后必须被修改。默认值为 99999, 表示不进行限制
警告时间提前多少天警告用户密码将过期 , 默认值为 7 天 ,0 表示不提供警告
不活跃时间密码过期多少天后禁用此用户
失效时间密码失效日期 , 以距离 1970 年 1 月 1 日的天数表示 , 默认为空 , 表示永久可用
 
标志保留未用,以便以后发展之用

linux中存储组信息的文件是哪个?且其中的字段是什么意思?

(3 )用户组账号文件 ——/etc/group
系统中的每个组,在 /etc/group 文件中有一行记录,任何用户均可以读取用户组账户信息配置文件。
[root@192 ~]# head -1 /etc/group
root:x:0:
 

Groupname组的名字
password组的加密口令
GID是系统区分不同组的 ID ,在 /etc/passwd 域中的 GID 字段是用这个数来指定用户的基本组
Userlist是用 “ , ” 分开的用户名,列出的成员以该组为附加组

2.创建下列用户、组和组成员资格:
 1.创建名为 sysmgrs 的组

[root@192 ~]# groupadd sysmgers

 2.创建用户 natasha 同时指定sysmgrs作为natasha的附加组

[root@192 ~]# useradd -g sysmgers natasha

 3.创建用户 harry 同时指定 sysmgrs作为harry的附加组

[root@192 ~]# useradd -g sysmgers harry

 4.创建用户 sarah 指定shell类型为/sbin/false(无权访问系统上的交互式 shell) 且不是 sysmgrs 的成员

root@192 ~]# useradd sarsh -s /sbin/false

 5.设置natasha 、 harry 和 sarah 的密码都是 123

[root@192 ~]# passwd natasha
Changing password for user natasha.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@192 ~]# echo "123"|passwd --stdin harry
Changing password for user harry.
passwd: all authentication tokens updated successfully.
[root@192 ~]# echo "123"|passwd --stdin sarsh
Changing password for user sarsh.
passwd: all authentication tokens updated successfully.
[root@192 ~]# 

 6.创建用户lockuser, 并指定家目录为/home/lock, 然后锁定该用户

[root@192 ~]# useradd -d /home/lock lockuser
[root@192 ~]# usermod -L lockuser
[root@192 ~]# 

 7.创建用户limituser, gid为1555,userid为1666, 让其密码在10天后过期

[root@192 ~]# groupmod -g 1555 sysmgers
[root@192 ~]# useradd -g "1555" -u 1666 -f 10 limituser
[root@192 ~]# 

 8.解锁lockuser, 并设定下次登录时必须修改密码

[root@192 ~]# usermod -U lockuser
usermod: unlocking the user's password would result in a passwordless account.
You should set a password with usermod -p to unlock this user's password.
[root@192 ~]# passwd -e lockuser
Expiring password for user lockuser.
passwd: Success

 9.让natasha具备修改 harry密码的权限(sudo)


   visudo
   Host_Alias RHCSA=lwz
   User_Alias USER11=natasha
   Cmnd_Alias CHPASS=/usr/bin/passwd harry
   USER RCHSA=(root)  CHPASS
 

[root@192 ~]# vim /etc/sudoers
[root@192 ~]# su - natasha
[natasha@192 ~]$ sudo passwd harry
 
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:
 
    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.
 
[sudo] password for natasha: 


 10. 创建用户testuser并设置密码,修改用户名为normaluser   

[root@192 ~]# useradd testuser -p 123 ;usermod -l normaluser testuser
useradd: user 'testuser' already exists
[root@192 ~]# su - normaluser
[normaluser@192 ~]$ exit
logout
[root@192 ~]# su - testuser
su: user testuser does not exist
[root@192 ~]# 

 11.删除lockuser

[root@192 ~]# userdel lockuser
[root@192 ~]# su - lockuser
su: user lockuser does not exist
[root@192 ~]# 

4创建文件,并赋予权限611(两种方式,一种guoa,一种nnn)

[root@192 ~]# touch chmod.txt
[root@192 ~]# ls -l chmod.txt
-rw-r--r--. 1 root root 0 Jul 20 06:20 chmod.txt
[root@192 ~]# chmod g=x chmod.txt
[root@192 ~]# chmod o=x chmod.txt
[root@192 ~]# ls -l chmod.txt
-rw---x--x. 1 root root 0 Jul 20 06:20 chmod.txt
[root@192 ~]# chmod 611 chmod.txt
[root@192 ~]# ls -l chmod.txt
-rw---x--x. 1 root root 0 Jul 20 06:20 chmod.txt
[root@192 ~]# 

5.创建目录,并赋予权限755(两种方式,一种guoa,一种nnn)

[root@192 ~]# mkdir chmod1
[root@192 ~]# ll
total 64
drwxr-xr-x. 2 root root     6 Jul 20 06:23 chmod1
[root@192 ~]# chmod u=rwx chmod1
[root@192 ~]# chmod g=rx chmod1
[root@192 ~]# chmod o=rx chmod1
[root@192 ~]# ll
total 64
drwxr-xr-x. 2 root root     6 Jul 20 06:23 chmod1
[root@192 ~]# chmod 755 chmod1
[root@192 ~]# ls -l
total 64
drwxr-xr-x. 2 root root     6 Jul 20 06:23 chmod1
[root@192 ~]# 


6.创建文件,并将文件的属主和属组修改其他用户

[root@192 ~]# touch chown.txt
[root@192 ~]# chown :sysmagers chown.txt 
chown: invalid group: ‘:sysmagers’
[root@192 ~]# chown natasha chown.txt 

7.设置suid,为文件设置suid(两种方式 u+s和nnnn)的方式

[root@192 ~]# chmod u+s chown.txt 
[root@192 ~]# chmod 4 chown.txt 
[root@192 ~]# 

8.设置sgid, 为文件设置sgid(两种方式 g+s和nnnn)的方式

[root@192 ~]# chmod g+s chmod1
[root@192 ~]# chmod 2 chmod1
[root@192 ~]# 

9.设置sbit,为目录设置sbit(两种方式 o+t和nnnn)的方式

[root@192 ~]# chmod o+t chmod.txt 
[root@192 ~]# chmod 1 chmod.txt 
[root@192 ~]# 

10.创建文件,查询文件的acl

[root@192 ~]# touch acltest
[root@192 ~]# getfacle acltest 
bash: getfacle: command not found...
Similar command is: 'getfacl'
[root@192 ~]# getfacl acltest 
# file: acltest
# owner: root
# group: root
user::rw-
group::r--
other::r--
[root@192 ~]# 

    为文件设置acl 用户为testuser1 权限为 rwx

[root@192 ~]# setfacl -m u:testuser1:rwx acltest
[root@192 ~]# getfacl acltest
# file: acltest
# owner: root
# group: root
user::rw-
user:testuser1:rwx
group::r--
mask::rwx
other::r--
[root@192 ~]# 
 

    为文件设置acl的mask: 权限为r-x

[root@192 ~]# setfacl -m m:r-x acltest
[root@192 ~]# getfacl acltest 
# file: acltest
# owner: root
# group: root
user::rw-
group::r--
mask::r-x
other::r--
[root@192 ~]# 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值