创建文件和目录时的默认权限umask

1.概念

linux系统中文件的默认权限是在/etc/bashrc文件中记载着:
 # By default, we want umask to get set. This sets it for non-login shell.
    # Current threshold for system reserved uid/gids is 200
    # You could check uidgid reservation validity in
    # /usr/share/doc/setup-*/uidgid file
    if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then
       umask 002    //一般用户默认权限
    else
       umask 022   //root用户默认权限
    fi


    # Only display echos from profile.d scripts if we are no login shell
    # and interactive - otherwise just process them to set envvars

可以使用umask命令查看默认权限
[root@zhangyong zy]# umask -S
u=rwx,g=rx,o=rx

linux系统规定文件的默认最大权限是666,目录的默认最大权限是777,那么umask=022 需要反过来看就是755(u=rwx,g=rx,o=rx),所以对应权限:
1.目录:022->755(u=rwx,g=rx,o=rx)
2.文件:022->644(u=rw,g=rx,o=rx)

2.修改默认权限


[root@zhangyong zy]# umask
0022
[root@zhangyong zy]# umask 002
[root@zhangyong zy]# umask
0002
[root@zhangyong zy]#



你可能感兴趣的:(Linux)