Why change the owner of a symbolic link in linux

symlink

In linux it's possible to change the owner or the group owner of a symbolic link (symlink). I was wondering why someone would want to do that, since permissions of a symlink are not used when accessing a file through it.

I can only imagine one use case where it could be useful: to allow a user to delete a symlink in a directory with sticky bit.

Do you know other cases where it might be useful to change the owner or group owner of a symlink ?

Best Answer

Suppose root is working in a directory that Eve can write to. There's a file foo in this directory that needs to be changed to belong to Eve. So root types chown eve foo. But just before root hits Enter, Eve runs ln -sf /etc/passwd foo. Now /etc/passwd belongs to Eve! If root can run chown -h eve foo to make sure not to follow symlinks, then the most harm that can be done is that some other file in the same directory has been changed to belong to Eve.

lchown is also convenient when you're changing the owner of a directory tree. You don't need to worry about accidentally affecting a file outside the tree because you called chown on a symbolic link.

Related Question