权限管理
权限查看及读取
- 权限查看
ls -l file #查看文件权限
ls -ld dir #查看目录权限
普通权限的类型及作用
- 用户对文件的身份
- 权限位
- 权限类型
设定普通权限的方法
chmod
#复制权限
chmod -R --reference=/tmp /mnt/westosdir #复制/tmp目录的权限到/mnt/westosdir及目录中的子文件;-R递归复制
#字符方式设定权限
chmod <a|u|g|o><+|-|=><r|w|x> file
chmod a+x /mnt/file1
chmod u+x,g-x /mnt/file1
chmod u=rx /mnt/file1
#数字方式设定权限
r = 4; w = 2; x = 1
chmod 644 /mnt/file1
系统默认权限设定
umask
umask #查看保留权力
umask 权限值 #临时设定系统预留权力
文件默认权限 = 777-umask-111
目录默认权限 = 777-umask
umask值越大系统安全性越高
vim /etc/bashrc #shell系统配置文件
vim /etc/profile #系统环境配置文件
source /etc/bashrc #source作用时使我们更改的内容立即被系统识别
source /etc/profile
文件用户用户组管理
chown chgrp
chown username file #更改文件拥有者
chgrp groupname file #更改文件拥有组
chown username:groupname file #同时更改文件的拥有者和拥有组
chown -R user dir #更改目录本身及目录中内容的拥有者
特殊权限
- stickyid 粘制位
chmod 1777 /mnt/pub/
chmod o+t /mnt/pub/ #这两条命令均可以添加该权限
公共目录任意用户可增删文件
仅建立文件者可以删除
- sgid 强制位
chmod 2777 /mnt/pub/
chmod g+s /mnt/pub/ #这两条命令均可以添加该权限
#监视该进程
watch -n 1 'ps ax -o user,group,comm | grep cat'
- suid 冒险位
chmod 4777 file
chmod u+s file
acl权限列表
- 功能
- acl列表开启标识
- acl列表权限读取
getfacl westosfile
- acl列表权限控制
setfacl -m u:westos:0 westosfile #设定
setfacl -m g:westos:rw westosfile
setfacl -m u::rwx westosfile
setfacl -m g::0 westosfile
setfacl -x u:westos westosfile #删除列表中的westos
setfacl -b westosfile #关闭
- acl 权限优先级
- mask
恢复:
setfacl -m m:westos:rwx /mnt/pub
- 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权限
i #不能作任何的更改
a #能添加不能删除
lsattr dir|file #查看attr权限
chattr +i|+a|-i|-a dir|file #设定attr权限
- test2
建立目录完成以下要求
*新建目录/ sc / cw / js / pub
/ sc 目录是生产部内的数据存储目录, 只能被生产部内的人员读写
/ cw 目录是财务部门的数据存储目录,只能被财务部门的人员读写
/ js 目录是技术部内的数据存储目录,只能被技术部内的人员读写
/ pub 为公司人员公共目录,可以被公司任何员工读写
- test3
建立目录完成以下要求
*新建目录/ sc / cw / js / pub
/ sc 目录是生产部内的数据存储目录, 只能被生产部内的人员读写,并且在sc中建立的文件都属于生产部门
/ cw 目录是财务部门的数据存储目录,只能被财务部门的人员读写,并且在cw中建立的文件都属于财务部门
/ js 目录是技术部内的数据存储目录,只能被技术部内的人员读写,并且在js中建立的文件都属于技术部门
/ pub 为公司人员公共目录,可以被公司任何员工读写,但只能删除自己的文件