For example, I have foo.sh with 770 permissions. When I do:
ln -s foo.sh bar.sh
The link bar.sh has 2777 permissions. Why is this? I thought they were meant to be inherited?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The permissions on a symbolic link are largely immaterial. They are normally 777 as modified by the umask setting.
The POSIX standard for
symlink()says:POSIX provides an
lchown()system call; it does not provide anfunction.lchmod()(On my MacOS X 10.7.1, with umask 022, a newly created symlink ends up with 755 permissions; with umask 002, the permissions end up as 775. So, the observation that links are created with 770, 700 etc permissions may be accurate; the permissions settings are still immaterial, and do not affect the usability of the symlink.)
Further investigations about symlinks on RHEL 5 and MacOS X
On Linux (RHEL 5 for x86_64; kernel 2.6.18-128.el5), I only get to see 777 permissions on a symlink when it is created:
I ran that in a sub-shell so the umask setting was not permanent.
On MacOS X (10.7.1), I get to see variable permissions on a symlink:
Note that this is the same command sequence (give or take the file name) linked to.
On MacOS X, the
chmodcommand has an option-hto change the permissions on a symlink itself:On MacOS X, the permissions on the symlink matter; you can’t read the symlink unless you have read permission on the symlink (or you’re root). Hence the error in the
lsoutput above. Andreadlinkfailed. Etc.On MacOS X,
chmod -h 100 pqr(execute) allows me to use the link (cat pqrworks) but not to read the link. By contrast,chmod -h 400 pqrallows me to both read the link and use the link. And for completeness,chmod -h 200 pqrallows me to use the link but not to read it. I assume, without having formally tested, the similar rules apply to group and other.On MacOS X, then, it seems that read or write permission on a symlink allows you to use it normally, but execute permission alone means you cannot find where the link points (
readlink(2)fails) even though you can access the file (or, presumably, directory) at the other end of the link.Conclusion (subject to modification):
The MacOS X behaviour is an extension of the behaviour mandated by POSIX – or deviation from the behaviour mandated by POSIX. It complicates life slightly. It means that you have to ensure that anyone who is supposed to use the link has permission to do so. This is normally trivial (
umask 022means that will be the case).The underlying system call for
chown -hon MacOS X issetattrlist(2).