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

    4418040-8d10538d130aaf2e

    关于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

  • 相关阅读:
    电力企业信息化建设方案之调度信息报送系统
    HP QC IE11不支持( win7 64位 无法安装)解决方法
    ajax传递list集合
    mysql主从配置
    js动态获取地址栏后的参数
    html页面保存数的两种方式
    微信开发之八 页面获取周围beacon设备
    最好的时光在路上,最美的风景在远方
    【摄影】田子坊
    【前端统计图】echarts实现简单柱状图
  • 原文地址:https://www.cnblogs.com/hgmyz/p/12351159.html
Copyright © 2011-2022 走看看