319
59
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?
319
59
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?
391
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
1Thank goodness you found out what the reason was! Cheers – zigojacko – 2015-03-25T17:11:26.340
Had the same problem but wasn't putting the slash. Turns out that -h arguement is very important! – Antony D'Andrea – 2015-05-11T09:03:38.740
10I can't believe after 4 years, I have bumped into my past self suffereing the same problem, the missin '-h'! – Antony D'Andrea – 2015-07-13T09:49:46.213
1@AntonyD'Andrea well, you're certainly older ... :-P – pepoluan – 2016-03-16T10:53:13.823
9doesn't work for me on ubuntu – Radek – 2010-09-25T01:07:45.560
2Wow, this took me hours to find. – defines – 2011-04-19T11:36:07.807
54@Radek It worked for me on Ubuntu so long as I remembered the -h
flag. – IQAndreas – 2013-06-11T15:04:58.343
31Works for me on Ubuntu with -h
and without the trailing slash. – friederbluemle – 2014-02-12T02:44:33.127
29
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
2For 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)” – Matijs – 2014-07-13T22:50:13.497
7
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/
5
Is the target a file or a directory?
If it is a directory then try -H (upper case H)
6Sorry for the thread necromancy, but I'd like to point out that the correct syntax is with the lowercase 'h'. – None – 2010-06-18T14:07:52.490
the target is a directory – None – 2009-11-09T13:09:32.477
see my edited reply about directory – None – 2009-11-09T13:13:48.787
4
simply.
chown -h myuser:mygroup <symlink> [without trailing slash]
should be enough and work!
3
Recreate that link by myuser at myuser's home, and mv this link to the target location by sudo.
For example:
(as myuser), ln -s somedir/ linkname
(will be a broken link if somedir/ doesn't exist in user's directory)
Then, sudo mv linkname targetlocation
(will become a valid link provided targetlocation/somedir/
exists)
Your answer is without detail and hard to fully understand. Please consider revising your answer to provide more detail. – James Mertz – 2012-07-13T04:20:37.707
1
For Solaris (verified on S11.3) for a symbolic link to a directory you will need to run
root@ac11x017:/var/tmp$ ls -lal dumpdir
lrwxrwxrwx 1 root root 16 Jun 15 09:08 dumpdir -> /data/dumpdir/
root@ac11x017:/var/tmp$ chown -RP oracle:oinstall dumpdir
lrwxrwxrwx 1 oracle oinstall 16 Jun 15 09:09 dumpdir -> /data/dumpdir/
1
I had a similar problem. For me, I could not chmod the symbolic link even as root regardless how I called chmod. To add confusion to this, nautilus was showing the owner/group as nothing. The owner was just blank. So I tried to change the symbolic link using nautilus running as root since chmod wasn't working and nautilus crashed!!
But I think I figured out the problem. The directory the symbolic link was pointing to had different permissions than the symbolic link. So I chmod'ed the target directory (using -h) to my user/group name. Then chmod'ed the symbolic link to the same and it worked! And viewing the symbolic link's details in nautilus (with root permissions) now no longer crashes.
So for others having a similar problem, check the permissions of the target directory/file and make sure it is compatible with the permissions you are setting the symbolic link to.
1
Note that changing the owner
of a symlink can only work if the target is accessible by the new user you want to assign it to.
For instance, if your target is inside a folder that the user you want to assign it to doesn't have enough rights, the ln -s command
behavior is such that it will do nothing at all.
Are you on a NFS mount? – Ortomala Lokni – 2017-01-23T10:19:43.820
Anything that ends with
/
is a directory. You meanmysymbolic
, which is the symbolic link, notmysymbolic/
which is probably the directory it points to. – David Schwartz – 2017-12-05T11:11:21.843Which 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. – Jichao – 2009-11-09T13:09:31.743