加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 如何让多个用户访问chmod()相同的文件?

发布时间:2020-12-14 02:33:40 所属栏目:Linux 来源:网络整理
导读:我有一个系统,其中多个用户正在运行一个chmod相同文件的应用程序.我尝试使用setacl将两个用户添加为文件的用户所有者来执行此操作,但它不起作用.由于chmod系统调用失败,应用程序出错. 见例子: [jacob@macbook-debian ~/Projects/test] getfacl bin/testfile
我有一个系统,其中多个用户正在运行一个chmod相同文件的应用程序.我尝试使用setacl将两个用户添加为文件的用户所有者来执行此操作,但它不起作用.由于chmod系统调用失败,应用程序出错.

见例子:

[jacob@macbook-debian ~/Projects/test] getfacl bin/testfile
# file: bin/testfile
# owner: root
# group: root
user::rwx
user:jacob:rwx
user:jason:rwx
group::r-x
group:www-data:rwx
mask::rwx
other::r-x


[jacob@macbook-debian ~/Projects/test] chmod 0755 bin/testfile
chmod: changing permissions of 'bin/testfile': Operation not permitted

解决方法

在添加用户时使用Linux ACL,您不会将它们添加为文件的所有者.只是打开/修改和写入该文件的权限.
当调用chown或chmod时,有效用户ID将是例如. jacob和那个将匹配所有者的价值.如果不匹配,则命令将失败.

从男人2 chmod.

The effective UID of the calling process must match the owner of the file,or the process must be privileged (Linux: it must have the CAP_FOWNER capability).

另一种方法是将所描述的能力设置为调用进程/二进制chmod.但这会打开一个很大的安全问题,因为每个人都可以使用此命令来更改权限.
Here是一个关于用户访问功能的细粒度的线程,但它似乎不是很直接.

根据您的用例的限制,您可能希望为用户添加sudo规则以使用chmod,或者您评估用户必须在他们不拥有的文件上运行chmod的原因.也许在文件创建期间使用umask就足够了.

如果您的用户属于对目录具有写入权限的组,您还可以复制有问题的文件,删除原始文件并将副本移动到原始名称.这将导致用户将拥有复制的文件并可以执行chmod.

[user@localhost testdir]$ll
total 12K
drwxrwxr-x  2 root user 4.0K Jul 14 11:49 .
drwxr-xr-x  3 user user 4.0K Jul 14 11:47 ..
-rw-rw----+ 1 root user    5 Jul 14 11:41 testfile
[user@localhost testdir]$getfacl testfile 
# file: testfile
# owner: root
# group: user
user::rw-
user:user:rw-
group::rw-
group:user:rw-
mask::rw-
other::---

[user@localhost testdir]$chmod 777 testfile
chmod: changing permissions of 'testfile': Operation not permitted
[user@localhost testdir]$cp -a testfile testfile.copy
[user@localhost testdir]$getfacl *
# file: testfile
# owner: root
# group: user
user::rw-
user:user:rw-
group::rw-
group:user:rw-
mask::rw-
other::---

# file: testfile.copy
# owner: user
# group: user
user::rw-
user:user:rw-
group::rw-
group:user:rw-
mask::rw-
other::---

[user@localhost testdir]$mv testfile.copy testfile
[user@localhost testdir]$ll
total 12K
drwxrwxr-x  2 root user 4.0K Jul 14 11:50 .
drwxr-xr-x  3 user user 4.0K Jul 14 11:47 ..
-rw-rw----+ 1 user user    5 Jul 14 11:41 testfile

[user@localhost testdir]$chmod 777 testfile
[user@localhost testdir]$ll
total 12K
drwxrwxr-x  2 root user 4.0K Jul 14 11:50 .
drwxr-xr-x  3 user user 4.0K Jul 14 11:47 ..
-rwxrwxrwx+ 1 user user    5 Jul 14 11:41 testfile

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读