chown is not changing symbolic link

356,154

Solution 1

I was putting a slash in the end of target:

chown -h myuser:mygroup mysymbolic/ 

just removed the slash in the end and works. Here's the correct way:

 chown -h myuser:mygroup mysymbolic

Solution 2

I've tried this myself and it works for me. If you have the -h it changes the owner of the symbolic link, but if you dont then it changes the owner of the file itself and not the link.

But it doesnt seem to work of the symbolic link is linked to a directory

Solution 3

I was unable to chown a directory even with -h but using the full path worked.

# ls -al
drwxr-xr-x 2 deploy deploy 4096 Dec 30 10:29 .
drwxr-xr-x 3 deploy deploy 4096 Dec 30 08:59 ..
lrwxrwxrwx 1 root   root     32 Dec 30 09:02 apps -> /u/apps/
# chown -h deploy:deploy apps
# ls -al
drwxr-xr-x 2 deploy deploy 4096 Dec 30 10:29 .
drwxr-xr-x 3 deploy deploy 4096 Dec 30 08:59 ..
lrwxrwxrwx 1 root   root     32 Dec 30 09:02 apps -> /u/apps/
# chown -h deploy:deploy apps/
# ls -al
drwxr-xr-x 2 deploy deploy 4096 Dec 30 10:29 .
drwxr-xr-x 3 deploy deploy 4096 Dec 30 08:59 ..
lrwxrwxrwx 1 root   root     32 Dec 30 09:02 apps -> /u/apps/
# pwd 
/var/www/html
# chown -h deploy:deploy /var/www/html/apps
# ls -al
drwxr-xr-x 2 deploy deploy 4096 Dec 30 10:29 .
drwxr-xr-x 3 deploy deploy 4096 Dec 30 08:59 ..
lrwxrwxrwx 1 deploy deploy   32 Dec 30 09:02 apps -> /u/apps/

Solution 4

Is the target a file or a directory?

If it is a directory then try -H (upper case H)

Solution 5

simply.

chown -h myuser:mygroup <symlink> [without trailing slash]

should be enough and work!  

Share:
356,154

Related videos on Youtube

Admin
Author by

Admin

Updated on September 17, 2022

Comments

  • Admin
    Admin over 1 year

    I'm trying to change the user/group of a symbolic link with the command:

    $ chown -h myuser:mygroup mysymbolic/ 
    

    But it's not changing. I'm logged in as root. The current user/group is set to root:root. What went wrong?

    • Jichao
      Jichao over 14 years
      Which operating system do you use?Acoording to the manaul page,-h option takes affect only on systems that can change the ownership of symbolic link.
    • Ortomala Lokni
      Ortomala Lokni over 7 years
      Are you on a NFS mount?
    • David Schwartz
      David Schwartz over 6 years
      Anything that ends with / is a directory. You mean mysymbolic, which is the symbolic link, not mysymbolic/ which is probably the directory it points to.
  • Admin
    Admin over 14 years
    the target is a directory
  • Admin
    Admin over 14 years
    see my edited reply about directory
  • Admin
    Admin almost 14 years
    Sorry for the thread necromancy, but I'd like to point out that the correct syntax is with the lowercase 'h'.
  • Radek
    Radek over 13 years
    doesn't work for me on ubuntu
  • defines
    defines about 13 years
    Wow, this took me hours to find.
  • IQAndreas
    IQAndreas almost 11 years
    @Radek It worked for me on Ubuntu so long as I remembered the -h flag.
  • friederbluemle
    friederbluemle over 10 years
    Works for me on Ubuntu with -h and without the trailing slash.
  • Matijs
    Matijs almost 10 years
    For what it's worth, the man page on OS X is a lot clearer on the -h option than the one on (Arch) Linux. “-h If the file is a symbolic link, change the user ID and/or the group ID of the link itself.” vs. “-h, --no-dereference affect symbolic links instead of any referenced file (useful only on systems that can change the ownership of a symlink)”
  • zigojacko
    zigojacko about 9 years
    Thank goodness you found out what the reason was! Cheers
  • Antony D'Andrea
    Antony D'Andrea about 9 years
    Had the same problem but wasn't putting the slash. Turns out that -h arguement is very important!
  • Antony D'Andrea
    Antony D'Andrea almost 9 years
    I can't believe after 4 years, I have bumped into my past self suffereing the same problem, the missin '-h'!
  • pepoluan
    pepoluan about 8 years
    @AntonyD'Andrea well, you're certainly older ... :-P
  • Layne Bernardo
    Layne Bernardo almost 4 years
    If you chown a symlink like that it actually affects the referenced files. If you want to change the symlink itself you need to use the switch -h, or –no-dereference