五、汇总Linux系统中的权限管理( 二 )


vim /etc/bashrc#shell系统配置文件74 if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then75 umask 002#普通用户的umask76 else77 umask 022 -- 077#root用户的umask78 fivim /etc/profile#系统环境配置文件59 if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then60 umask 002#普通用户的umask61 else62 umask 022 -- 077#root用户的umask63 fisource /etc/bashrc#source作用是使我们更改的内容立即被系统识别source /etc/profile
[root@westos_student50 Desktop]# vim /etc/bashrc[root@westos_student50 Desktop]# source /etc/bashrc[root@westos_student50 Desktop]# vim /etc/profile[root@westos_student50 Desktop]# source /etc/profile[root@westos_student50 Desktop]# umask0077
五、文件用户、用户组管理
chownfile?? ##更改文件拥有者
chgrpfile ??##更改文件拥有组
chown . file ?##同时更改文件的拥有者和拥有组
chown|chgrp -R user|group dir? ##更改目录本身及目录中内容的拥有者或者拥有组
[root@westos_student50 Desktop]# touch /mnt/file{1..3}[root@westos_student50 Desktop]# mkdir /mnt/dir[root@westos_student50 Desktop]# touch /mnt/dir/test[root@westos_student50 Desktop]# chown gong /mnt/file1[root@westos_student50 Desktop]# chgrp gong /mnt/file1[root@westos_student50 Desktop]# chown gong.gong /mnt/file3[root@westos_student50 Desktop]# chown gong /mnt/dir[root@westos_student50 Desktop]# chgrp gong /mnt/dir[root@westos_student50 Desktop]# chown root.root /mnt/dir[root@westos_student50 Desktop]# chown -R gong.gong /mnt/dir(加“.”可以实现同时更改目录及目录中内容的拥有者或拥有组)
六、特殊权限
(1) #粘制位
#针对目录: #如果一个目录开启,那么这个目录中的文件只能被文件所有人删除
设定方式:
①源文件权限 dir
②chmod o+t dir或chmod o-t dir
(2)sgid #强制位
#针对目录: 目录中新建的文件自动归属到目录的所属组中
设定方式:
①chmod 2源文件权限 dir
②chmod g+s dir或chmod g-s dir
注意:
#只针对二进制的可执行文件(c程序)
#当运行二进制可执行文件时都是用文件拥有组身份运行,和执行用户无关
(3)suid #冒险位
设定方式:
①chmod 4原属性 file
②chmod u+s file或chmod u-s file
注意:
#只针对二进制的可执行文件(c程序)
#当运行二进制可执行文件时都是用文件拥有者身份运行,和执行用户无关
七、acl:访问控制列表
Lists #访问控制列表
功能:在列表中可以设定特殊用户对与特殊文件有特殊权限
#acl列表开启标识
-rw-rw---- 1 root caiwu 0 Apr 18 09:03
没有"+“代表acl列表未开启
-rw-rw----+ 1 root caiwu 0 Apr 18 09:03
有”+"代表acl列表功能开启
getfacl westosfile#acl列表权限读取显示内容分析# file: westosfile#文件名称# owner: root#文件拥有者# group: root#文件拥有组user::rw-#文件拥有者权限user:lee:rw-#特殊指定用户权限group::r--#文件拥有组权限group:westos:---#特殊指定的用户组的权限mask::rw-#能够赋予特殊用户和特殊用户组的最大权限阀值other::r--#其他人的权限
注意:
当文件权限列表开启,不要用ls -l 的方式来读取文件的权限!!!
#acl列表的控制setfacl -m u:lee:rw westosfile#设定setfacl -m g:westos:rw westosfilesetfacl -m u::rwx westosfilesetfacl -m g::0 westosfilesetfacl -x u:lee westosfile#删除列表中的leesetfacl -b westosfile#关闭
acl 权限优先级
拥有者 > 特殊指定用户 > 权限多的组 >权限少的组 > 其他