What is the Ubuntu equivalent of OSX `chmod -h` flag?

Solution 1:

Not possible. There is no way since permissions on a symlink are meaningless (a symlink is not a file; it only points to a file). The way to do this with Linux is through ACL though.

symlink are explained as...

The values of the file mode bits for the created symbolic link are unspecified. All interfaces specified by POSIX.1-2008 shall behave as if the contents of symbolic links can always be read, except that the value of the file mode bits returned in the st_mode field of the stat structure is unspecified.


The difference is here: chmod and chmod... it is BSD versus Linux.


Not sure if it is important but regarding SSH: it uses stat(2), not lstat(2) to get the permissions.

  • stat() stats the file pointed to by path and fills in buf.
  • lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to.

Solution 2:

You can't. The underlying chmod system call simply doesn't support this in Linux, and for that matter, Linux doesn't care about the link's permissions either. From 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.

As for hard links or bind mounts, the source's permissions are used, so none of the three standard ways to reflect a file's contents elsewhere can help you in this.