前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Linux文件/目录的权限及归属管理使用

Linux文件/目录的权限及归属管理使用

作者头像
砸漏
发布2020-10-22 11:11:48
1.3K0
发布2020-10-22 11:11:48
举报
文章被收录于专栏:恩蓝脚本

一、文件的权限和归属概述

1、访问权限

读取r:允许查看文件内容、显示目录列表; 写入w:允许修改文件内容,允许在目录中新建、移动、删除文件或子目录; 可执行x:允许运行程序、切换目录

2、归属(所有权)

属主:拥有该文件或目录的用户账号; 属组:拥有该文件或目录的组账号;

3、查看文件的权限和归属

Linux文件/目录的权限及归属管理精讲
Linux文件/目录的权限及归属管理精讲

4、chmod设置文件权限

chmod命令的基本语法格式如下:

Linux文件/目录的权限及归属管理精讲
Linux文件/目录的权限及归属管理精讲

应用举例:

代码语言:javascript
复制
[root@centos01 ~]# touch 1.txt   <!--创建1.txt文件-->
[root@centos01 ~]# ll 
总用量 8
-rw-r--r-- 1 root root  0 1月 11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod u+x ./1.txt <!--属主用户添加执行权限-->
[root@centos01 ~]# ll
总用量 8
-rwxr--r-- 1 root root  0 1月 11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod u-x,g+x,o+w 1.txt  
<!--属主用户取消执行权限,组添加执行权限,其他用户添加写入权限-->
[root@centos01 ~]# ll
总用量 8
-rw-r-xrw- 1 root root  0 1月 11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chmod 755 1.txt <!--添加755权限(rwxr-xr-x)-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x 1 root root  0 1月 17 02:36 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

5、chown设置文件的归属

chown命令的基本语法格式如下:

Linux文件/目录的权限及归属管理精讲
Linux文件/目录的权限及归属管理精讲

应用举例:

代码语言:javascript
复制
[root@centos01 ~]# chown bob 1.txt <!--1.txt设置属主-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x 1 bob root  0 1月 17 02:36 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chown :benet 1.txt <!--1.txt设置属组-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x 1 bob benet  0 1月 17 02:36 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# chown bob:benet 1.txt <!--1.txt设置属主和属组-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x 1 bob benet  0 1月 17 02:36 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
<!---->

二、目录的权限和归属

1、访问权限

Linux文件/目录的权限及归属管理精讲
Linux文件/目录的权限及归属管理精讲

2、归属(所有权)

属主:拥有该目录的用户账号;

属组:拥有该目录的组账号;

3、chmod设置目录权限

chmod命令设置目录权限的基本格式如下:

Linux文件/目录的权限及归属管理精讲
Linux文件/目录的权限及归属管理精讲

应用举例:

代码语言:javascript
复制
[root@centos01 ~]# chmod -R 755 benet/  
     <!--循环设置benet目录下的文件或者目录权限为755-->
[root@centos01 ~]# ll
总用量 8
-rw-r-xrw- 1 root root  0 1月 11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
drwxr-xr-x 3 root root  18 1月 11 22:39 benet
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

4、chown设置目录的归属

chown命令设置目录归属的基本格式如下:

Linux文件/目录的权限及归属管理精讲
Linux文件/目录的权限及归属管理精讲

应用举例:

代码语言:javascript
复制
[root@centos01 ~]# chown -R bob:benet benet/  
  <!--循环设置benet目录中所属用户为bob,所属组为benet-->
[root@centos01 ~]# ll
总用量 8
-rw-r-xrw- 1 root root   0 1月 11 22:27 1.txt
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
drwxr-xr-x 3 bob benet  18 1月 11 22:39 benet
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

三、权限掩码umask

1、umask的作用

控制新建的文件或目录的权限,默认权限去除umask的权限就是新建的文件或者目录的权限。

2、设置umask

代码语言:javascript
复制
umask 022

3、查看umask

代码语言:javascript
复制
umask

4、应用举例:

代码语言:javascript
复制
[root@centos01 ~]# umask <!--查看umask-->
0022
[root@centos01 ~]# umask 000 <!--设置umask为000-->
[root@centos01 ~]# umask  <!--验证是否设置成功-->
0000
[root@centos01 ~]# touch 2.txt  <!--创建新文件-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x 1 bob benet  0 1月 17 03:48 1.txt
-rw-rw-rw- 1 root root   0 1月 17 03:48 2.txt  <!--查看权限-->
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg
[root@centos01 ~]# umask 022    <!--设置umask为022-->
[root@centos01 ~]# umask      <!--查看umask-->
0022
[root@centos01 ~]# touch 3.txt    <!--再次创建新文件-->
[root@centos01 ~]# ll
总用量 8
-rwxr-xr-x 1 bob benet  0 1月 17 03:48 1.txt
-rw-rw-rw- 1 root root   0 1月 17 03:48 2.txt
-rw-r--r-- 1 root root   0 1月 17 03:49 3.txt <!--查看权限,明显不一样-->
-rw-------. 1 root root 1572 10月 23 22:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1603 10月 23 23:36 initial-setup-ks.cfg

以上就是本文的全部内容,希望对大家的学习有所帮助。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-09-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
访问管理
访问管理(Cloud Access Management,CAM)可以帮助您安全、便捷地管理对腾讯云服务和资源的访问。您可以使用CAM创建子用户、用户组和角色,并通过策略控制其访问范围。CAM支持用户和角色SSO能力,您可以根据具体管理场景针对性设置企业内用户和腾讯云的互通能力。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档