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.
Syntax
$ 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.
See also
Read man pages by typing the following command:
$ man chown
$ man ls
You can also see Linux version of chown command man page here and BSD/Unix version of chown here online at FreeBSD project.
🐧 5 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • 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 |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
can i give to permission for link file in linux
soft links permissions are only for renaming the soft link and removal of the link itself thus the 777 permissions are not at all valid for changing the contents of the original file, or changing the contents of the file it shows through the cat command
you can set with recursive option of ‘chown’; note that this will change the target permissions as well.
bash$ chown -R root:root
Hi, the webhost we are using disallows 0777 on directories which basically prevents me from using symbolic links on www/ dir, what can we do about this? not use symlink at all?
Sure you can. It’s as simple as:
chown -h user:user /path/to/symbolic/link
From chown help: