• linux 的文件权限案列


    需求:

    技术部门人员可以相互查看,但不能删除和修改别人的文件,其他部门人员不能查看,但领导组可以且只能查看。

    设计:

    技术部: 组 jishu ; 人员 js1, js2
    领导组: 组 lingd ; 人员 ld1
    其他部门: 组 other ; 人员 wrm

    1.新建自定义扩展组

    [root@rhel8-client02 home]# groupadd jishu
    [root@rhel8-client02 home]# groupadd lingd
    [root@rhel8-client02 home]# groupadd other
    [root@rhel8-client02 home]# cat /etc/group
    。。。。。。省略。。。。。。。

    jishu❌1000:
    lingd❌1001:
    other❌1002:

    2.新建用户 并放到对应的扩展用户组

    [root@rhel8-client02 home]# useradd -N -G jishu js1
    [root@rhel8-client02 home]# useradd -N -G jishu js2
    [root@rhel8-client02 home]# useradd -N -G lingd ld1
    [root@rhel8-client02 home]# useradd -N -G other wrm
    # -N 表示不创建和用户同名基本用户组,-G 表示加入一个或多个扩展用户组

    3.新建共享文件夹并赋权

    [root@rhel8-client02 home]# mkdir -p /share/jishu
    [root@rhel8-client02 home]# ls -ld /share/jishu/
    drwxr-xr-x. 2 root root 6 Aug 25 14:27 /share/jishu/
    [root@rhel8-client02 home]# chown -R root:jishu /share/jishu/ #修改所属技术组
    [root@rhel8-client02 home]# ls -ld /share/jishu/
    drwxr-xr-x. 2 root jishu 6 Aug 25 14:27 /share/jishu/
    [root@rhel8-client02 home]# chmod -R 3770 /share/jishu/ #此文件夹下创建的东西默认扩展组为技术部门并不能修改和删除其他人的文件或文件夹,(用到了文件的特殊权限,SGID + SBIT)。
    [root@rhel8-client02 home]# ls -ld /share/jishu/
    drwxrws--T. 2 root jishu 6 Aug 25 14:27 /share/jishu/

    4.领导可以查看

    [root@rhel8-client02 home]# setfacl -m g:lingd:rx /share/jishu
    [root@rhel8-client02 etc]# getfacl /share/jishu/
    getfacl: Removing leading '/' from absolute path names
    # file: share/jishu/
    # owner: root
    # group: jishu
    # flags: -st
    user::rwx
    group::rwx
    group:lingd:r-x
    mask::rwx
    other::---

    #用到了文件访问控制列表,单个精准控制。

    5.备份还原权限

    [root@rhel8-client02 home]# cd /
    [root@rhel8-client02 /]# getfacl -R share > share.acl #备份ACL权限
    [root@rhel8-client02 /]# setfacl --restore share.acl #还原ACL权限
    #一般建议,在修改权限是先做备份

  • 相关阅读:
    Python 细聊从暴力(BF)字符串匹配算法到 KMP 算法之间的精妙变化
    cygwin编译wget过程记录
    SDL2.0播放pcm格式音频
    算法|每日一题|切割后面积最大的蛋糕|贪心
    安全高效应对混合办公新趋势 腾讯四大协同办公产品亮相
    含氯甲基大孔径苯乙烯-二乙烯基苯微球/交联聚苯乙烯微球固载双齿席夫碱型氧钒(Ⅳ)
    (十七)admin-boot项目之国际化支持
    第三方代开的微信小程序更换管理员
    用python实现音乐下载
    劳动工资电子台账操作流程
  • 原文地址:https://www.cnblogs.com/wlbl-dd/p/16626417.html