zoukankan      html  css  js  c++  java
  • Linux文件默认权限和umask笔记

    640?wx_fmt=jpeg



    关于Linux文件默认权限的问题,可以实际先尝试一下如下命令:

    root用户登录

    [root@localhost test]# touch file1

    [root@localhost test]# ls-l file1

    -rw-r--r-- 1 root root 0 May  5 08:28 file1 #输出结果 对应的数字权限 644

    [root@localhost test]# touch file2

    [root@localhost test]# ls-l file2

    -rw-r--r-- 1 root root 0 May  5 08:29 file2 #输出结果 对应的数字权限 644

    [root@localhost test]# mkdir dir1

    [root@localhost test]# ls-ld dir1

    drwxr-xr-x 2 root root 4096 May  5 08:29 dir1 #输出结果 对应的数字权限 755

    [root@localhost test]# mkdir dir2

    [root@localhost tmp]# ls-ld dir2

    drwxr-xr-x 2 root root 4096 May  5 08:29 dir2 #输出结果 对应的数字权限 755

    user1用户登录

    [user1@localhost test]# touch file1

    [user1@localhost test]# ls-l file1

    -rw-rw-r-- 1 root root 0 May  5 08:28 file1 #输出结果 对应的数字权限 664

    [user1@localhost test]# touch file2

    [user1@localhost test]# ls-l file2

    -rw-rw-r-- 1 root root 0 May  5 08:29 file2 #输出结果 对应的数字权限 664

    [user1@localhost test]# mkdir dir1

    [user1@localhost test]# ls-ld dir1

    drwxrwxr-x 2 root root 4096 May  5 08:29 dir1 #输出结果 对应的数字权限 775

    [user1@localhost test]# mkdir dir2

    [user1@localhost tmp]# ls-ld dir2

    drwxrwxr-x 2 root root 4096 May  5 08:29 dir2 #输出结果 对应的数字权限 775

    通过上面的执行结果可以得出以下结论:如果是root用户创建的文件默认权限是644,目录默认权限是755;普通用户创建的文件默认权限是664,目录默认权限是775.两者的默认权限是不同的,造成两者用户权限不同的原因就是Linux针对不同的用户创建文件和创建目录默认的权限不同,Linux系统通过umask(遮罩)的概念来控制相应的权限。可以在/etc/profile 文件中进行查看。

    内容如下(51-55行):

    if [ $UID-gt 99 ] && [ "`id-gn`" = "`id-un`" ]; then

        umask 002

    else

        umask 022

    fi

    通过上面的文件内容可以看出:如果UID>99 设置的umask值为002,如果UID不大于99则umask值为022.关于遮罩计算权限的方式如下:比如 777 用字符串表示 rxwrwxrwx,如果遮罩值是022 对于的字符串是 ----w--w-,计算方法是如果遮着包含字母的,计算出真正的权限就不包含该位置的字母用-代替即可,个人理解公式:遮罩值+计算的真正权限=rxwrwxrwx

    上面的权限可以这样理解: ----w--w-+rxwr-xr-x=rxwrwxrwx

  • 相关阅读:
    [LeetCode] 304. Range Sum Query 2D
    [LeetCode] 303. Range Sum Query
    [Google] Help employee find the nearest gbike
    Difference between Process and thread?
    Given a family tree, find out if two people are blood related
    [LeetCode] 676. Implement Magic Dictionary 实现神奇字典
    [LeetCode] 659. Split Array into Consecutive Subsequences 将数组分割成连续子序列
    [LeetCode] 815. Bus Routes 公交路线
    [LeetCode] 129. Sum Root to Leaf Numbers 求根到叶节点数字之和
    mybatis example 使用AND 和OR 联合查询
  • 原文地址:https://www.cnblogs.com/hgmyz/p/12351279.html
Copyright © 2011-2022 走看看