How to change permissions for a symbolic link under Linux/UNIX


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.

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.

🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • satish Dec 14, 2007 @ 10:42

    can i give to permission for link file in linux

  • saransh srivastava Apr 18, 2010 @ 11:07

    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

  • coolfire Jun 19, 2012 @ 6:52

    you can set with recursive option of ‘chown’; note that this will change the target permissions as well.

    bash$ chown -R root:root

  • Albert Jan 28, 2014 @ 21:52

    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?

  • Adam P Jul 17, 2020 @ 13:03

    Sure you can. It’s as simple as:
    chown -h user:user /path/to/symbolic/link

    From chown help:

      -h, --no-dereference   affect symbolic links instead of any referenced file
                             (useful only on systems that can change the
                             ownership of a symlink)
    

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.