Can I set the permissions on a symbolic link under Linux/UNIX? How do I change permissions for a symbolic link?
No, you cannot. If you try to execute chmod command on a symbolic link, it will return with error Changing permissions of `filename’: Operation not permitted. This is quite logical, as permission on a symbolic link is meaningless. The only thing is important is permission on the file that the link points. In short, permissions on a symbolic link do not really mean anything. However, we have some command line option that allows to set or change permissions for a symbolic link.
How to change or set permissions on a symbolic link
The chown command line changes the user ID (UID) and the group ID (GID) of the given files. Symbolic links named by arguments are slently left unchanged unless -h is used. Hence, try the following syntax affect symbolic links instead of any referenced file. Useful only on systems that can change the ownership of a symlink on GNU/Linux.
$ chown -h vivek:vivek /path/to/file
$ chown --no-dereference username:groupname /path/to/file
Verify it using the ls command:
$ ls -l filename
$ ls -l /path/to/link
lrwxrwxrwx 1 www ftpusers 11 Jul 17 23:10 www -> /var/www/html
A note about BSD/macOS Unix chown command for symbolic link
The syntax is as follows:
$ chown -h user1:group1 filename
$ sudo chown -h www:ftpuser /var/www/html
If the file is a symbolic link, change the user ID and/or the group ID of the link itself. You may have to use the sudo command or su command to change permissions.
|Category||List of Unix and Linux commands|
|Network Utilities||dig • host • ip • nmap|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|