rsync 权限问题——目标权限未正确应用

发布于 2024-10-01 07:43:04 字数 1459 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遮了一弯 2024-10-08 07:43:04

--chmod 会覆盖发送端权限,但如果您未指定-p--perms无论如何,都会使用目标默认值(即忽略 --chmod)。

来自 man 1 rsync

--chmod

此选项告诉 rsync 应用一个或多个逗号分隔的
“chmod”字符串表示传输中文件的权限。
结果值被视为权限
发送方为文件提供,这意味着
此选项似乎对现有文件没有影响,如果
--perms 未启用

--chmod overrides the sending side permissions, but if you don't specify -p or --perms as well then the destination defaults are used regardless (i.e. --chmod is ignored).

From man 1 rsync:

--chmod

This option tells rsync to apply one or more comma-separated
"chmod" strings to the permission of the files in the transfer.
The resulting value is treated as though it was the permissions
that the sending side supplied for the file, which means that
this option can seem to have no effect on existing files if
--perms is not enabled
.

天气好吗我好吗 2024-10-08 07:43:04

您必须将 --chmod-p 选项一起使用,如下所示:

$ rsync -avz --chmod=o-rwx -p tata/ tata2/

这是一个完整的测试:

在文件夹中创建一些文件

$ mkdir tata
$ mkdir tata2
$ cd tata
$ touch tyoto
$ touch tiuti

默认权限是: u=rw, g=r, o=r

$ ls -l 
total 0
-rw-r--r-- 1 romain users 0 fév 16 11:48 tiuti
-rw-r--r-- 1 romain users 0 fév 16 11:48 tyoto

尝试不带参数的 rsync

$ cd ..
$ rsync -avz tata/ tata2/

目标权限与源文件相同

$ ls -l tata2
total 0
-rw-r--r-- 1 romain users 0 fév 16 11:48 tiuti
-rw-r--r-- 1 romain users 0 fév 16 11:48 tyoto

指定 rsync 选项 --chmod=o-rwx -p

$ rsync -avz --chmod=o-rwx -p tata/ tata2/
$ ls -l tata2
total 0
-rw-r----- 1 romain users 0 fév 16 11:48 tiuti
-rw-r----- 1 romain users 0 fév 16 11:48 tyoto

现在你的烫发就可以了。

You have to use --chmod with -p options, like this:

$ rsync -avz --chmod=o-rwx -p tata/ tata2/

And here is a full test:

Create some file in a folder

$ mkdir tata
$ mkdir tata2
$ cd tata
$ touch tyoto
$ touch tiuti

The default perms are: u=rw, g=r, o=r

$ ls -l 
total 0
-rw-r--r-- 1 romain users 0 fév 16 11:48 tiuti
-rw-r--r-- 1 romain users 0 fév 16 11:48 tyoto

Try an rsync without params

$ cd ..
$ rsync -avz tata/ tata2/

The destination perms are the same than the source files

$ ls -l tata2
total 0
-rw-r--r-- 1 romain users 0 fév 16 11:48 tiuti
-rw-r--r-- 1 romain users 0 fév 16 11:48 tyoto

Specify the rsync options --chmod=o-rwx -p

$ rsync -avz --chmod=o-rwx -p tata/ tata2/
$ ls -l tata2
total 0
-rw-r----- 1 romain users 0 fév 16 11:48 tiuti
-rw-r----- 1 romain users 0 fév 16 11:48 tyoto

And now your perms are ok.

瀞厅☆埖开 2024-10-08 07:43:04

我认为您需要添加 --perms (又名 -p)。引用手册页:

关闭此选项时,权限设置如下:

...

新文件的“正常”权限位设置为
源文件的权限被接收屏蔽
目录的默认权限(接收
进程的 umask,或通过指定的权限
目标目录的默认 ACL),以及它们的特殊
权限位被禁用,除非有新的
目录从其父目录继承 setgid 位。

我怀疑您的目标系统有一个典型的 umask,如 022,它会阻止 rsync 设置组写入位。不幸的是 --chmod 没有提到 umask 如何应用或不应用。

I think you need to add --perms (aka -p). Quoting from the manpage:

When this option is off, permissions are set as follows:

...

New files get their "normal" permission bits set to the
source file's permissions masked with the receiving
directory's default permissions (either the receiving
process's umask, or the permissions specified via the
destination directory's default ACL), and their special
permission bits disabled except in the case where a new
directory inherits a setgid bit from its parent directory.

I suspect your destination system has a typical umask like 022 which is preventing the group write bit from being set by rsync. Unfortunately --chmod doesn't mention how the umask does or does not apply.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文