OSX `chmod -h` 标志的 Ubuntu 等价物是什么?

Ray*_*tre 13 ssh permissions chmod symbolic-link

在 OSX 中,我可以设置符号链接本身的权限(而不是使用 -h 指向的内容)。从手册页:

 -h      If the file is a symbolic link, change the mode of the link itself rather than the file that the link points to.
Run Code Online (Sandbox Code Playgroud)

在 Ubuntu 14.04 中,我尝试设置符号链接的权限,但它仅在符号链接目标上设置。

它是关于从一个符号链接/home/nagios/.ssh/someprivatekey/somewhere/else/privatekey,这样的权限是SSH重要。我怎样才能做到这一点?

Rin*_*ind 18

不可能。没有办法,因为符号链接的权限没有意义(符号链接不是文件;它只指向一个文件)。不过,在 Linux 上执行此操作的方法是通过ACL

符号链接被解释为...

创建的符号链接的文件模式位的值是未指定的。POSIX.1-2008 指定的所有接口都应该表现为符号链接的内容总是可以读取的,除了在 stat 结构的 st_mode 字段中返回的文件模式位的值是未指定的。


不同之处在于:chmodchmod ......它是 BSD 与 Linux。


不确定它是否重要,但关于 SSH:它使用 stat(2)而不是 lstat(2) 来获取权限。

  • stat() 统计path指向的文件并填充buf。
  • lstat() 与 stat() 相同,除了如果 path 是符号链接,则链接本身是 stat-ed,而不是它引用的文件。

  • 顺便说一句,POSIX 确实指定了 `fchmodat` 函数,该函数可用于更改符号链接的模式(可选功能 - 不支持它的系统,包括 Linux,返回错误 EOPNOTSUPP),但在 `chmod` 命令中没有使用这个。在 POSIX 中只定义了 `-R`。 (4认同)
  • 即使在最新版本中也没有指定在符号链接上设置权限的能力,它是一个 BSD 扩展。 (2认同)
  • 符号链接权限 _在 Linux 上毫无意义 **_。在可以更改它们的系统上(使用 `lchmod(2)` 或 `fchmodat(2)`...),它们确实具有含义(允许/拒绝 `readlink()`(读取)或通过它们进行路径解析(执行))。写入权限通常不会,因为您无法更改符号链接的目标。 (2认同)

mur*_*uru 9

你不能。底层chmod系统调用在 Linux 中根本不支持这一点,因此,Linux 也不关心链接的权限。来自man chmod

chmod never changes the permissions of symbolic links; the chmod system
call cannot change their permissions.  This is not a problem since  the
permissions  of  symbolic  links  are  never  used.   However, for each
symbolic link listed on the command line, chmod changes the permissions
of  the  pointed-to  file.   In  contrast, chmod ignores symbolic links
encountered during recursive directory traversals.
Run Code Online (Sandbox Code Playgroud)

至于硬链接或绑定挂载,使用源的权限,因此在其他地方反映文件内容的三种标准方法中没有一种可以帮助您。