美文网首页
文件权限管理和默认权限

文件权限管理和默认权限

作者: 一秃脚丫子 | 来源:发表于2020-05-03 10:57 被阅读0次

    一、权限管理##

    ...
    1、对文件的所有者,和所属组以及其它用户权限编辑
    [16:35:06 root@centos data]#ll
    total 8
    -rw-r--r--. 1 centos centos 28 Apr 24 16:59 1.txt
    -rw-r--r--. 1 centos1 centos 72 Apr 24 14:20 2.txt
    -rw-r--r--. 1 root root 0 Apr 24 11:55 stdout.log
    [16:56:52 root@centos data]#chmod u-w,g-r,o-r 1.txt
    [16:57:31 root@centos data]#ll
    total 8
    -r--------. 1 centos centos 28 Apr 24 16:59 1.txt
    -rw-r--r--. 1 centos1 centos 72 Apr 24 14:20 2.txt
    -rw-r--r--. 1 root root 0 Apr 24 11:55 stdout.log
    ...
    删除文件,和文件本身权限没有关系,和文件夹权限有关系;
    当前用户在此文件夹中的权限满足时,才可对文件进行操作;
    a+X可对文件夹下的子文件夹添加执行权限,而不是文件
    也可以给添加过执行文件的文件添加执行权限(避免安全风险)

    [09:40:53 root@centos data]#ll
    total 8
    -rw-r--r-- 1 root root 9 May 3 09:39 1.txt
    -rw-r--r-- 1 root root 13 May 3 09:40 2.txt
    drwxr-xr-x 2 root root 6 May 3 09:36 subdir
    [09:40:55 root@centos data]#chmod u+x 2.txt
    [09:41:05 root@centos data]#ll
    total 8
    -rw-r--r-- 1 root root 9 May 3 09:39 1.txt
    -rwxr--r-- 1 root root 13 May 3 09:40 2.txt
    drwxr-xr-x 2 root root 6 May 3 09:36 subdir
    [09:41:12 root@centos data]#ll -d /data
    drwxr-xr-x. 3 root root 46 May 3 09:40 /data
    [09:49:41 root@centos data]#chmod -R a+X data
    chmod: cannot access 'data': No such file or directory
    [09:50:18 root@centos data]#chmod -R a+X /data
    [09:50:23 root@centos data]#ll
    total 8
    -rw-r--r-- 1 root root 9 May 3 09:39 1.txt
    -rwxr-xr-x 1 root root 13 May 3 09:40 2.txt
    drwxr-xr-x 2 root root 6 May 3 09:36 subdir
    [09:50:25 root@centos data]#
    数字法:权限:rwx为 421;
    7rwx rx 5 rw 6 4 r ;

    二、新建文件和目录的默认权限

    umask 的值可以用来保留在创建文件权限;
    1、新建文件的默认权限:666-umask;如果所得结果某位存在执行(奇数)权限,则将其权限+1
    2、新建目录的默认权限:777-umask;
    3、全局设置: /etc/bashrc
    3.1、用户设置: ~/.bashrc
    4.文件权限
    文件的权限总共有三种:r(可读),w(可写),x(可执行)
    1)文件权限的作用
    r
    对文件 是否可以查看文件中的字符
    对目录 是否可以查看目录中有什么文件
    w
    对文件 是否可以改变文件中记录的字符
    对目录 是否可以在目录中管理文件,是否可以更改目录中文件的元数据
    x
    对文件 是否可以通过文件名称调用文件内记录的程序
    对目录 是否可以进入此目录

    注意:删除文件需要w和x的权力
    r和x权限基本上是都给或者都不给
    w权限出现在rx之后
    chattr +i 文件 来定义重要文件;用chattr-i可以去掉;

    相关文章

      网友评论

          本文标题:文件权限管理和默认权限

          本文链接:https://www.haomeiwen.com/subject/fenzwhtx.html