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

  • 相关阅读:
    Java线程状态及Thread类中的主要方法
    Kali Linux 装好系统后安装经常使用软件
    Setup SSH and SVN on Windows Server
    sql plus 抢救数据(測)
    利用用户自己的server、tomcat下的解决iOS7.1企业应用无法安装应用程序 由于证书无效的问题
    mysql基本操作【重要】
    Mybatis逆向工程——(十四)
    lucene查询索引之QueryParser解析查询——(八)
    lucene查询索引之Query子类查询——(七)
    lucene修改索引——(六)
  • 原文地址:https://www.cnblogs.com/hgmyz/p/12351278.html
Copyright © 2011-2022 走看看