我遇到SFTP和SCP的问题,其中复制的文件不会inheritance远程父目录的权限。 我曾经在服务器上看到类似的问题,其中SFTP / SCP会话的umask被修改,但是,这并不一定解决我的问题,因为有些目录需要有不同的权限。 因此,我不会有一个默认的umask集。
因此,我想强制复制的文件具有远程系统上父目录设置的权限。 基本上,我希望SCP / SFTP以与没有 -p选项的cp相同的方式工作。 目前SFTP / SCP模仿cp -p行为。
这是我想要发生的事情:
1.)用户想要复制文件foo.txt的权限:
-rw -------。 1用户用户0 Feb 29 09:08 foo.txt
2.)用户使用SCP将foo.txt复制到目录/bar下的服务器上。 /bar有权限(setgid设置):
drwxrws --- + 3 root usergroup 4096 Feb 28 12:19 bar
3.) /bar具有以下facl的集合:
用户:: RWX 组:: RWX 组:用户组:RWX 默认:用户:: RWX 默认:组:: RWX 默认:组:用户组:RW-
4.) foo.txt 应该具有以下权限(和facl):
-rw-rw ---- + 1 user usergroup 0 Feb 29 09:33 foo.txt 用户:: RW- group :: rwx #effective:rw- 组:用户组:RW-
5.)相反, foo.txt有权限:
-rw ------- + 1 user usergroup 0 Feb 29 09:36 foo.txt 用户:: RW- group :: rwx #effective:--- group:usergroup:rw- #effective:---
有没有简单的方法来获取文件获得预期的权限?
另外,我的事情是有意义的,还是多余的?
编辑:修复后显示正常。 (Serverfault的代码和编号不太好,我需要把东西包装在pre标签中。)
从手册页:“当scp复制文件时,目标文件是使用某些文件属性创build的,缺省情况下,文件权限在目标主机上附加一个umask,修改和上次访问时间是复制的时间或者,您可以告诉scp复制原始文件的权限和时间戳,-p选项可以完成此操作。
根据上面的信息,我不知道你想要什么,而不使用cronjob来设置权限。 umask选项仅适用于正在创build的文件。 Setgid仅适用于该组。 我相信你可以写一个recursion设置权限的工作,但是我能想到的只有在我误解了这个问题的情况下,才会导致你的描述。
通过SSHpipe理猫命令。 这将创build文件(所以它inheritance了权限),然后它将填充内容。 例如,要将本地文件foo放在remoteHost上,并inheritance由setfacl设置的权限:
ssh user@remoteHost "/bin/cat > /pathOnRemoteServer/foo" < foo
如果您可以select使用rsync ,则可以对权限进行一些额外的控制。 特别是,请查看--perms选项下的文本。 因此,在手册页上:
In summary: to give destination files (both old and new) the source permissions, use --perms. To give new files the destina- tion-default permissions (while leaving existing files unchanged), make sure that the --perms option is off and use --chmod=ugo=rwX (which ensures that all non-masked bits get enabled). If you'd care to make this latter behaviour easier to type, you could define a popt alias for it, such as putting this line in the file ~/.popt (the following defines the -Z option, and includes --no-g to use the default group of the destination dir): rsync alias -Z --no-p --no-g --chmod=ugo=rwX You could then use this new option in a command such as this one: rsync -avZ src/ dest/