1. linux系统中,创建一个新的文件或者目录的时候,新的文件或目录都会有默认的访问权限,umask命令与文件和目录的默认访问权限有关。
    用户创建一个文件,文件的默认权限为 -rw-rw-rw-(666) ,创建目录的默认权限 drwxrwxrwx (777),umask值则表明了需要从默认权限中去掉哪些权限来成为最终的默认权限值
2. 查看umask值
    umask
    修改umask值
    umask 026
    当umask为偶数:
    创建文件的权限为:666-026
    当umask为奇数:
    umask 025
    创建文件权限为:666-025然后在奇数位上加1,权限为666-025+001=642
  目录权限为:777-025=752 umask 055 文件权限为:666-055+011=622
  目录权限为:777-055=722
  临时设置umask,退出后失效
3. 永久修改umask的方法:
    vim /etc/profile
if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then
#[ 用户UID>=199 ] 并且  [ 用户的名字 == 用户组名字 ]
    umask 002
else
    umask 022

fi
source /etc/profile

    或者修改:
    修改文件/etc/bashrc,在文件中添加一行 umask 027

  

4. 文件系统的权限
[root@harbor ~]# chattr +a b
[root@harbor ~]#
[root@harbor ~]#
[root@harbor ~]#
[root@harbor ~]# lsattr b
-----a---------- b
[root@harbor ~]# echo 123 > b
-bash: b: Operation not permitted
[root@harbor ~]# echo 123 >> b
[root@harbor ~]# chattr -a b
[root@harbor ~]# cat b
123
[root@harbor ~]# lsattr b
---------------- b
[root@harbor ~]# echo "hello" > b
5. 测试i权限
[root@harbor ~]# ll c
-rw--w--w- 1 root root 0 Oct 31 14:20 c

[root@harbor ~]# chattr +i c

[root@harbor ~]# ll c
-rw--w--w- 1 root root 0 Oct 31 14:20 c
[root@harbor ~]# lsattr c
----i----------- c
[root@harbor ~]# echo 123 >> c
-bash: c: Permission denied
[root@harbor ~]# echo 123 > c
-bash: c: Permission denied
[root@harbor ~]# chattr -i c
[root@harbor ~]# echo 123 > c
[root@harbor ~]# cat c
123
[root@harbor ~]# chattr +i c
[root@harbor ~]# echo 1234 >> c
-bash: c: Permission denied
[root@harbor ~]# rm -f c
rm: cannot remove ‘c’: Operation not permitted
[root@harbor ~]# chattr -i c
[root@harbor ~]# rm -f c
5. t 粘滞位
    设置了粘滞位的目录在目录下面创建的文件只能管理自己的文件
ll -d /tmp/
drwxrwxrwt. 9 root root 195 Oct 31 14:32 /tmp/

6. suid权限
    运行包含suid权限的 命令的时候,相当于这个命令的所有者
[root@harbor ~]# ls
anaconda-ks.cfg  go  harbor-online-installer-v1.8.2.tgz  keepalived-2.0.18.tar.gz  test.txt  zookeeper.out

[root@harbor ~]# su test

[test@harbor root]$ ls
ls: cannot open directory .: Permission denied
[test@harbor root]$ rm -f /root/test.txt
rm: cannot remove ‘/root/test.txt’: Permission denied

[test@harbor ~]$ exit
exit

[root@harbor ~]# ll /bin/rm
-rwxr-xr-x. 1 root root 62864 Apr 11  2018 /bin/rm
[root@harbor ~]# chmod u+s /bin/rm
[root@harbor ~]# !ll
ll /bin/rm
-rwsr-xr-x. 1 root root 62864 Apr 11  2018 /bin/rm
[root@harbor ~]# su test

[test@harbor root]$ rm -f /root/test.txt
[test@harbor root]$ exit
exit

[root@harbor ~]# chmod u-s /bin/rm
[root@harbor ~]# ls
anaconda-ks.cfg  go  harbor-online-installer-v1.8.2.tgz  keepalived-2.0.18.tar.gz  zookeeper.out

文件的权限,有x权限时+s为小s,没有x时+s为大S
[root@harbor ~]# ll test.txt
-rw--w--w- 1 root root 12 Oct 31 14:56 test.txt
[root@harbor ~]# chmod u+s test.txt
[root@harbor ~]# !ll
ll test.txt
-rwS-w--w- 1 root root 12 Oct 31 14:56 test.txt
[root@harbor ~]# chmod +x test.txt
[root@harbor ~]# !ll
ll test.txt
-rws-w--w- 1 root root 12 Oct 31 14:56 test.txt

  

  

  

  

  

01-12 20:09