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

我有一个系统,其中多个用户正在运行一个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

相关文章

1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...
如何抑制stable_secret读取关键的“net.ipv6.conf.all.stabl...
1 删除0字节文件 find -type f -size 0 -exec rm -rf {} ...
## 步骤 1:安装必要的软件包 首先,需要确保系统已安装 `dh...