ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

Linux权限的操作

2022-02-22 20:03:06  阅读:215  来源: 互联网

标签:rw Feb 22 -- py wq Linux 操作 权限


Linux权限操作

  •   Linux用户组

    字母 代表的用户
    u 所有者
    g 用户组
    o 其他用户
    a 所有用户
  • linux权限

     字母 数字  权限 
     r  1
     w  2 写 
     x 4 执行 
    例如:
    -rw-rw-r--:所有者拥有读写的权限,组员拥有读写的权限,其他用户拥有读的权限
    -rwxrw-r--:所有者拥有读写执行的权限,组员拥有读写的权限,其他用户拥有读的权限
    -rwxrwxrwx:所有用户都拥有读写跟执行的权限
  •  chmod:更改权限

    • 通过权限数字更改用户的权限

      读的权限数字是1,写的权限数字是2,执行的权限数字是4
      
      同时有读写的权限就是3,有写执行的权限就是6,有所有权限就是7


      需求:给所有者给读写的权限,组员跟其他用户给所有权限
      [wq@centos-master a]$ ls -ll
      total 8
      -rwx--x-w- 1 wq wq 123 Feb 22 17:55 index.py
      -rw-rw-r-- 1 wq wq   0 Feb 22 18:49 readme.txt
      -rw-rw-r-- 1 wq wq 509 Feb 22 17:09 type.py
      [wq@centos-master a]$ chmod 377 index.py
      [wq@centos-master a]$ ls -ll
      total 8
      --wxrwxrwx 1 wq wq 123 Feb 22 17:55 index.py
      -rw-rw-r-- 1 wq wq   0 Feb 22 18:49 readme.txt
      -rw-rw-r-- 1 wq wq 509 Feb 22 17:09 type.py

       给所有用户给读写跟执行的权限

      [wq@centos-master a]$ ls -ll
      total 8
      --wxrwxrwx 1 wq wq 123 Feb 22 17:55 index.py
      -rw-rw-r-- 1 wq wq   0 Feb 22 18:49 readme.txt
      -rw-rw-r-- 1 wq wq 509 Feb 22 17:09 type.py
      [wq@centos-master a]$ chmod 777 index.py
      [wq@centos-master a]$ ls -ll
      total 8
      -rwxrwxrwx 1 wq wq 123 Feb 22 17:55 index.py
      -rw-rw-r-- 1 wq wq   0 Feb 22 18:49 readme.txt
      -rw-rw-r-- 1 wq wq 509 Feb 22 17:09 type.py
    • 通过权限字母更改权限

      • 增加权限:chmod 用户字符+权限字母  文件/目录

        给所有者添加写的权限
        [wq@centos-master a]$ ls -ll
        total 8
        ---x--x--x 1 wq wq 123 Feb 22 17:55 index.py
        [wq@centos-master a]$ chmod u+w index.py
        [wq@centos-master a]$ ls -ll
        total 8
        --wx--x--x 1 wq wq 123 Feb 22 17:55 index.py

         给组员添加所有权限

        [wq@centos-master a]$ ls -ll
        total 8
        --wx--x--x 1 wq wq 123 Feb 22 17:55 index.py
        [wq@centos-master a]$ chmod g+wrx index.py
        [wq@centos-master a]$ ls -ll
        total 8
        --wxrwx--x 1 wq wq 123 Feb 22 17:55 index.py

          给所有用户添加所有的权限

        [wq@centos-master a]$ ls -ll
        total 8
        --wxrwx--x 1 wq wq 123 Feb 22 17:55 index.py
        [wq@centos-master a]$ chmod a+rwx index.py
        [wq@centos-master a]$ ls -ll
        total 8
        -rwxrwxrwx 1 wq wq 123 Feb 22 17:55 index.py
      • 移除权限:chmod 用户字符-权限字母  文件/目录

        移除所有者的执行权限
        [wq@centos-master a]$ ls -ll
        total 8
        -rwxrwxrwx 1 wq wq 123 Feb 22 17:55 index.py
        -rw-rw-r-- 1 wq wq   0 Feb 22 18:49 readme.txt
        -rw-rw-r-- 1 wq wq 509 Feb 22 17:09 type.py
        [wq@centos-master a]$ chmod u-x index.py
        [wq@centos-master a]$ ls -ll
        total 8
        -rw-rwxrwx 1 wq wq 123 Feb 22 17:55 index.py
        -rw-rw-r-- 1 wq wq   0 Feb 22 18:49 readme.txt
        -rw-rw-r-- 1 wq wq 509 Feb 22 17:09 type.py
        移除组员的读写权限
        [wq@centos-master a]$ ls -ll
        total 8
        -rw-rwxrwx 1 wq wq 123 Feb 22 17:55 index.py
        -rw-rw-r-- 1 wq wq   0 Feb 22 18:49 readme.txt
        -rw-rw-r-- 1 wq wq 509 Feb 22 17:09 type.py
        [wq@centos-master a]$ chmod g-wr index.py
        [wq@centos-master a]$ ls -ll
        total 8
        -rw---xrwx 1 wq wq 123 Feb 22 17:55 index.py
        -rw-rw-r-- 1 wq wq   0 Feb 22 18:49 readme.txt
        -rw-rw-r-- 1 wq wq 509 Feb 22 17:09 type.py
        移除所有用户的执行权限
        [wq@centos-master a]$ ls -ll
        total 8
        -rwxrwxrwx 1 wq wq 123 Feb 22 17:55 index.py
        -rw-rw-r-- 1 wq wq   0 Feb 22 18:49 readme.txt
        -rw-rw-r-- 1 wq wq 509 Feb 22 17:09 type.py
        [wq@centos-master a]$ chmod a-x index.py
        [wq@centos-master a]$ ls -ll
        total 8
        -rw-rw-rw- 1 wq wq 123 Feb 22 17:55 index.py
        -rw-rw-r-- 1 wq wq   0 Feb 22 18:49 readme.txt
        -rw-rw-r-- 1 wq wq 509 Feb 22 17:09 type.py
    • 批处理文件.sh 的处理

      当我们首次运行一个批处理文件时,系统会提示我们无权限
      这时候我们可以看到我们是没有执行的权限的
      [wq@centos-master ~]$ ls
      asd.sh
      [wq@centos-master ~]$ ./asd.sh
      -bash: ./asd.sh: Permission denied
      [wq@centos-master ~]$ ls -ll
      total 4
      -rw-rw-r-- 1 wq wq 6 Feb 22 19:19 asd.sh
      我们需要增加一个执行的权限才能运行批处理文件
      [wq@centos-master ~]$ ls -ll
      total 4
      -rw-rw-r-- 1 wq wq 6 Feb 22 19:19 asd.sh
      [wq@centos-master ~]$ chmod 777 asd.sh
      [wq@centos-master ~]$ ls -ll
      total 4
      -rwxrwxrwx 1 wq wq 6 Feb 22 19:19 asd.sh
      [wq@centos-master ~]$ ./asd.sh
      Tue Feb 22 19:22:39 CST 2022
  •  运行shell脚本

    ./shell脚本名称

     

标签:rw,Feb,22,--,py,wq,Linux,操作,权限
来源: https://www.cnblogs.com/teangtang/p/15924674.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有