文件权限信息
- | rw-r--r-- | . | 1 | root | root | 0 | Apr 12 10:57 | westos
[1] [2] [3] [4] [5] [6] [7] [8] [9]
目录权限信息
d | rw-r--r-- | . | 2 | root | root | 0 | Apr 12 10:57 | westosdir
[1] [2] [3] [4] [5] [6] [7] [8] [9] 对于每一位的解释 [1] 文件类型
- 普通文件
d 目录
l 软连接
b 块设备
c 字符设备
s socket套接字
p 管道 |
[2] 用户权限
rw-|r--|r--
u g o
[3] 系统的selinux开启
[4] 对于文件:文件内容被系统记录的次数(硬链接个数)
对于目录:目录中子目录的个数
[5] 文件拥有者
[6] 文件拥有组
[7] 对于文件:文件内容大小
对于目录:目录中子文件的元数据大小
[8] 文件内容被修改的时间
[9] 文件名称
二,普通权限的类型及作用 3)用户对文件的身份 u:文件的所有者 g:文件的所有组 o:文件的其他用户 4)权限位 rwx |r-- |r-- 所有者的权限 所有组的权限 其他用户的权限 5)用户身份匹配 user>group>other 6)权限类型 - 未开启 r 对文件可读, 对目录可ls出目录中的文件 w 对文件可写 可以建立和删除目录 x 对文件可以调用 可以进入或者使用 三,设定普通权限的方法 1)chmod 文件权限设定 chmod --reference=/tmp /mnt/westosdir 复制/tmp目录的权限到/mnt/westosdir上 chmod -R--reference=/tmp /mnt/westosdir 复制/tmp目录中的权限到/mnt/westosdir及 文件的子目录 watch -n 1 ls -Rl /mnt 对/mnt进行监控 2)用字符方式设定权限 chmod u-rw /mnt/westos1 取消文件的所有者设定读写权限 chmod u-rw /mnt/westosfile1 chmod u-rw,g+x,o+wx /mnt/westosfile2 取消文件的所有者设定读写,所有组设定 执行权限,其他设定可写和执行权限 chmod a-rwx /mnt/westosfile3 取消文件所有权限 chmod u=rwx,g=rx,o=--- /mnt/westosfile4 设定文件所有者为所有读写执行 权限,所有组为读和执行权限,其他没有权限 chmod -R u=rwx,g=rx,o=--- /mnt/westosdir/ 所有者的rwx权限和所有组的rx权限 递归到testdir的子文件上 rwx=111=7 rw-=110=6 r-x=101=5 r--=100=4=r -wx=011=3 -w-=010=2=w --x=001=1=x ---=000=0 四,系统默认权限
umask值越大系统安全性越高
umask值:系统保留权力 umask 查看系统保留权限 umask 077 临时修改保留权限位077永久修改umask值 vim /etc/profile 59 if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then 60 umask 002 普通用户的umask 61 else 62 umask 022 -- 077 root用户的umask (将022改为077) 63 fi
vim /etc/bashrc 74 if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then 75 umask 002 #普通用户的umask 76 else 77 umask 022 -- 077 #root用户的umask 78 fi source /etc/profile 执行修改的权限 source /etc/bashrc
五,文件用户用户组管理 chown root westosfile 更改文件拥有者
chgrp root westosfile 更改文件拥有组 chown westos:westos westosfile 同时更改文件的拥有者和拥有组 chown|chgrp -R user|group dir 更改目录本身及目录中内容的拥有者或者拥有组 六,特殊权限 1)stickyid 粘制位(开启之后目录中文件只能被所有人删除) 开启命令:chmod o+t /pub 或 chmod 1777 /pub 2)sgid 强制位 开启后目录中新建的文件自动归属到目录的所属组中 开启命令:chmod g+s /bin/cat 或 chmod 2777 /bin/cat 3),sgid 只针对二进制的可执行文件(c程序) 当运行二进制可执行文件时都是用文件拥有组身份运行,和执行用户无关 watch -n 1 "ps ax -o users,group,comm | gerp cat" 进行监控
4),suid 只针对二进制的可执行文件(c程序) .当运行二进制可执行文件时都是用文件拥有者身份运行,和执行用户无关. chmod u+s /bin/watch su - westos /bin/cat ps ax -o user,group,comm | grep cat root westos cat 七,acl权限列表 acl=Access Control Lists=访问控制列表 -rw-rw----+ 1 root caiwu 0 Apr 18 09:03 westosfile 有+说明acl列表功能开启,权限列表开启后不能再使用ls-l的方式来读取文件权限 显示内容 file: westosfile 文件名称 # owner: root 文件拥有者 # group: root 文件拥有组 user::rw- 文件拥有者权限 user:lee:rw- 特殊指定用户权限 group::r-- 文件拥有组权限 group:westos:--- 特殊指定的用户组的权限 mask::rw- 能够赋予特殊用户和特殊用户组的最大权限阀值 other::r-- 其他人的权限 命令: [root@westos_student50 mnt]# ls -ld westosfile 查看权限
-rw-------. 1 root root 0 May 17 10:36 westosfile 没有开启acl列表
[root@westos_student50 mnt]# setfacl -m u:westos:rw /mnt/westosfile 添加用户westos到westosfile
[root@westos_student50 mnt]# getfacl /mnt/westosfile 查看权限
getfacl: Removing leading '/' from absolute path names
# file: mnt/westosfile
# owner: root
# group: root
user::rw-
user:westos:rw-
group::---
mask::rw-
other::--- [root@westos_student50 mnt]# setfacl -m o::r /mnt/westosfile 不改变其他,添加权限r [root@westos_student50 mnt]# setfacl -x u:westosuser /mnt/westosfile 取消westosuser [root@westos_student50 mnt]# setfacl -b /mnt/westosfile 关闭权限列表 -rwxrw-r--. 1 root root 0 May 17 10:36 /mnt/westosfile 已关闭 acl权限优先级
拥有者>特殊指定用户>权限多的组>权限少的组>其他 acl mask 控制 mask 能够给定特殊用户的最大权限值 注意:当设定完acl列表后,使用chmod修改权限mask就会出现问题 [root@westos_student50 mnt]# setfacl -m m::rwx /mnt/westosfile 此命令可修复mask值 acl列表默认权限
setfacl -m u:lee:rwx /mnt/westosdir 只对于/mnt/westosdir目录本身生效
setfacl -Rm u:lee:rwx /mnt/westosdir 对于/mnt/westosdir目录和目录中已经 存在的内容生 setfacl -m d:u:lee:rwx /mnt/westosdir/ 针对与/mnt/westosdir目录中新建文件生效
八,attr权限
attr权限限制所有用户
i 不能做任何更改
a 只能添加不能删除
lsattr dir | file 查看attr权限
chattr +i | +a | -i | -a dir | file 设定attr权限



