AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1079697
Accepted
NoobAdmin
NoobAdmin
Asked: 2021-10-06 23:24:26 +0800 CST2021-10-06 23:24:26 +0800 CST 2021-10-06 23:24:26 +0800 CST

在 CentOS 6 上,如何让用户创建的文件从其父目录继承权限?

  • 772

所以我们的服务器是这样设置的:
文件夹结构

/asic是我们大项目的文件夹,/200T是该大项目的子项目,下面的文件夹/200T是/lbh每个从事该子项目的工作人员的个人目录。/asic, /200T,/lbh都是由 root 创建的,然后由 root 通过和root重新配置它们的属性。和分别属于组和,而属于工作人员的用户帐户并属于组。chmod -Rchown -R/asic/200Trootasic200T/lbhlbhasic

这个想法是,所有工作的人都可以看到其中的内容,但/asic他们不能对这两个目录具有写访问权限——如果他们想创建一些东西,他们必须在自己的目录中执行此操作(等等) )。当一个工作人员在他们自己的目录中创建内容时,我们希望同一子项目的其他工作人员能够读取该新内容,但不会意外修改它。例如,刚刚在. 子项目上的另一个人 ( )应该能够读取但不能写入它们。如果要修改它们,他必须将它们复制到自己的目录中,然后再这样做。/200Tasic200T/lbhlbhtestbench.v/results/asic/200T/lbhglj200T/asic/200T/lbh/testbench.v/asic/200T/lbh/resultsglj/asic/200T/glj

为了达到上面的目的,我们需要默认to lbhbe创建的目录drwxr-s---和文件的权限rwxr-s---,然而现实是这样的:
lbh和root创建的文件和文件夹

导致每个工作人员都能够写入每个人自己的文件夹和文件,这正是我们试图避免的。的umask是,普通用户的root是。0022umask0002

我的问题:

  1. 为什么用户(like /lbh)在其个人目录(like)下创建的文件lbh忽略drwxr-s--- 了个人文件夹的权限,默认为 (d)rwxrwsr-x?
  2. 是否有安全的方法让工作人员默认使用 (d)rwxr-s--- 创建文件和文件夹?要求每个用户每次都手动操作 chmod太麻烦了,我担心更改默认umask值会导致新的意外问题。

非常感谢!


编辑: lbh 和 root 创建的文件的文件夹结构和权限如下所示:

[lbh@<machine> lbh]$ ls -al
total 16
drwxr-s---. 4 lbh  200T 4096 Oct  1 02:40 .
drwxr-sr-x. 4 root 200T 4096 Oct  1 02:18 ..
drwxrwsr-x. 2 lbh  200T 4096 Oct  1 02:26 aaa_lbh
drwxr-sr-x. 2 root 200T 4096 Oct  1 02:26 aaa_root
-rw-rw-r--. 1 lbh  200T    0 Oct  1 02:38 file_lbh.txt
-rw-r--r--. 1 root 200T    0 Oct  1 02:40 file_root.txt
[lbh@<machine> lbh]$ pwd
/asic/200T/lbh
[lbh@<machine> lbh]$ cd ..
[lbh@<machine> 200T]$ ls -al
total 16
drwxr-sr-x. 4 root 200T 4096 Oct  1 02:18 .
drwxr-x---. 3 root asic 4096 Oct  1 02:16 ..
drwxr-sr-x. 2 root 200T 4096 Oct  1 02:18 aaa
drwxr-s---. 4 lbh  200T 4096 Oct  1 02:40 lbh
[lbh@<machine> 200T]$ pwd
/asic/200T
[lbh@<machine> 200T]$ 

目录和getfacl文件的结果如下:

[lbh@<machine> Desktop]$ getfacl /asic
getfacl: Removing leading '/' from absolute path names
# file: asic
# owner: root
# group: asic
user::rwx
group::r-x
other::---

[lbh@<machine> Desktop]$ getfacl /asic/200T/
getfacl: Removing leading '/' from absolute path names
# file: asic/200T/
# owner: root
# group: 200T
# flags: -s-
user::rwx
group::r-x
other::r-x

[lbh@<machine> Desktop]$ getfacl /asic/200T/lbh
getfacl: Removing leading '/' from absolute path names
# file: asic/200T/lbh
# owner: lbh
# group: 200T
# flags: -s-
user::rwx
group::r-x
other::---

[lbh@<machine> Desktop]$ getfacl /asic/200T/lbh/aaa_lbh/
getfacl: Removing leading '/' from absolute path names
# file: asic/200T/lbh/aaa_lbh/
# owner: lbh
# group: 200T
# flags: -s-
user::rwx
group::rwx
other::r-x

[lbh@<machine> Desktop]$ getfacl /asic/200T/lbh/aaa_root/
getfacl: Removing leading '/' from absolute path names
# file: asic/200T/lbh/aaa_root/
# owner: root
# group: 200T
# flags: -s-
user::rwx
group::r-x
other::r-x

[lbh@<machine> Desktop]$ getfacl /asic/200T/lbh/file_lbh.txt 
getfacl: Removing leading '/' from absolute path names
# file: asic/200T/lbh/file_lbh.txt
# owner: lbh
# group: 200T
user::rw-
group::rw-
other::r--

[lbh@<machine> Desktop]$ getfacl /asic/200T/lbh/file_root.txt 
getfacl: Removing leading '/' from absolute path names
# file: asic/200T/lbh/file_root.txt
# owner: root
# group: 200T
user::rw-
group::r--
other::r--

[lbh@<machine> Desktop]$ touch hello.txt
[lbh@<machine> Desktop]$ mkdir hi 
[lbh@<machine> Desktop]$ ls -al
total 12
drwxr-xr-x.  3 lbh lbh 4096 Oct  9 17:28 .
drwx------. 36 lbh lbh 4096 Oct  9 17:21 ..
-rw-rw-r--.  1 lbh lbh    0 Oct  9 17:27 hello.txt
drwxrwxr-x.  2 lbh lbh 4096 Oct  9 17:28 hi
[lbh@<machine> Desktop]$ getfacl hi
# file: hi
# owner: lbh
# group: lbh
user::rwx
group::rwx
other::r-x

[lbh@<machine> Desktop]$ getfacl hello.txt 
# file: hello.txt
# owner: lbh
# group: lbh
user::rw-
group::rw-
other::r--

[lbh@<machine> Desktop]$ 
linux permissions file-permissions centos6
  • 1 1 个回答
  • 978 Views

1 个回答

  • Voted
  1. Best Answer
    Nikita Kipriyanov
    2021-10-06T23:57:32+08:002021-10-06T23:57:32+08:00

    Linux不支持权限继承,所以你不能做你在问题主题中提出的问题。

    您可以做的最好的事情是设置将应用于所有新创建的文件和目录的默认 POSIX ACL 。这不是继承,只是默认值:

    setfacl -m default:user:<username>:rwx <dir>
    setfacl -m default:group:<groupname>:rwx <dir>
    

    在此之后,如果有人在其中创建文件或目录(当然,如果他们被允许在那里创建对象),该对象将获得额外的 ACLuser:<username>:rwx和group:<groupname>:rwx. 您可以通过设置<username>和<groupname>空白来设置所有者和组所有者的默认权限。

    此“默认”只能在目录上设置,因为没有必要将其应用于文件。以这种方式设置的权限也会被 umask 屏蔽,因此如果在 umask 中删除了某个位,则该位将从权限中删除。例如,当你创建一个文件时,如果你不给它可执行位,它就不会成为可执行的(如预期的那样)。创建的子目录也将设置相同的“默认”ACL,因此其后代也将设置这些 ACL。您必须在创建后删除或更改子目录上的 ACL 才能停止此传播。

    使用 . 检查 ACL getfacl <dir>。当然,可能有几个这样的默认值(看起来你最终必须有几个规则);至少,我遇到的要求总是要求至少存在两个默认组 ACL)。


    您不能这样设置“默认文件所有者”,所有者将始终设置为创建进程有效的 uid。默认情况下,group-owner 将设置为进程 gid,但您可以通过使用父目录上的setgid位来更改它:

        chmod g+s <dir>
    

    之后,在该目录中创建的任何对象将默认复制其组所有者,即使创建用户不属于该组。这个 setgit 位传播到子目录。

    所有者可以将 group-owner 设置为他们所属的任何组。如果他们不属于由 setgid 派生的组,他们可以将他们的文件组所有者更改为他们所属的任何组,但之后他们将无法将其更改回 setgid 值。


    我想再次明确指出,这不是继承,这是设置不完全相同的默认值。如果您之后更改父对象上的某些内容,则已创建的对象将始终保留其在 Linux 中的权限。

    例如,在 Windows 中,当您将子对象 ACL 设置为“继承”时,更改父 ACL 将影响后代,这是正确的继承。

    • 0

相关问题

  • 多操作系统环境的首选电子邮件客户端

  • 你最喜欢的 Linux 发行版是什么?[关闭]

  • 更改 PHP 的默认配置设置?

  • 保护新的 Ubuntu 服务器 [关闭]

  • (软)Ubuntu 7.10 上的 RAID 6,我应该迁移到 8.10 吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve