rsync 许可?

lla*_*kin 6 linux rsync permissions

我已经运行了命令

sudo rsync --chmod=a+rwx testfile testfile2
Run Code Online (Sandbox Code Playgroud)

这将创建一个文件,testfile2但它的权限是755 (-rwxr-xr-x)

有人可以解释如何使它具有权限777 (-rwxrwxrwx)吗?

Pyl*_*lsa 12

sudo rsync --perms --chmod=777 testfile testfile2
Run Code Online (Sandbox Code Playgroud)

或者

sudo rsync --perms --chmod=a+rwx testfile testfile2
Run Code Online (Sandbox Code Playgroud)


aja*_*kel 5

将 --chmod=777 与 rsync 一起使用可能会失败:

sudo rsync --perms --chmod=777 ./testfile ./testfile2
rsync: Invalid argument passed to --chmod (777) 
rsync error: syntax or usage error (code 1) at main.c(1453) [client=3.0.9]
Run Code Online (Sandbox Code Playgroud)

但是,这些都是成功的:

sudo rsync --perms --chmod=u+rwx ./testfile ./testfile2
sudo rsync --perms --chmod=g+rwx ./testfile ./testfile2
sudo rsync --perms --chmod=o+rwx ./testfile ./testfile2
Run Code Online (Sandbox Code Playgroud)

即分别为用户 (u)、组 (g) 或其他 (o) 添加 (+) 权限。

另外 (a)=all 是成功的:

sudo rsync --perms --chmod=a+rwx ./testfile ./testfile2
Run Code Online (Sandbox Code Playgroud)

或者:

sudo rsync --perms --chmod=ugo+rwx ./testfile ./testfile2
Run Code Online (Sandbox Code Playgroud)

那 --perms 可以用 -p 替换,结果相同。

撤销 (-) 权限的工作方式相同,甚至是逗号分隔的添加和撤销组合:

sudo rsync --perms --chmod=u-rwx,o+rwx ./testfile ./testfile2
Run Code Online (Sandbox Code Playgroud)

  • `chmod 777`:不不不不!永远不要运行“chmod 777”。实际上从来不需要它!甚至不是为了“测试目的”。如果文件是可读的,那么它是可读的。如果需要写入的“用户”或“组”可写,则它是可写的。给予每个人写入权限的需求绝对为零,而忘记将其“chmod”恢复到正常状态正是跨国公司遭到黑客攻击的原因。只是不要这样做。曾经。我写了[Unix权限介绍](http://stackoverflow.com/a/35895436/660921)。请阅读它! (2认同)