If i understand it correctly, in linux, a file can have an arbitrary number of paths. Suppose some user wants to change permission of their /home/<user>
files so that all their files can't be read by other users. Intuitively it would make sense to run chmod o-r -R ~
. However, by my initial remark this seems like a potentially bad idea: there could be files in a (sub)directory of said user's home that are also in outside of it, and we wouldn't want to change the permissions of those. What should then be done instead?
Asked
Active
Viewed 72 times
0

Carla is my name
- 309
1 Answers
0
It's certainly true that files in a user's home
directory could be symlinks that point to files outside his home directory. And chmod
will change the permissions of the target of a symlink, as the permissions of the symlink itself are generally not used. But checking the man page for chmod
we see "chmod ignores symbolic links encountered during recursive directory traversals." So your stated command chmod o-r -R ~
will not affect anything that is not actually directly in your home directory.
A good place for more information on this is the man pages for chmod
, chown
, and ls
.

tsc_chazz
- 203
-
3
-
Fair point. But there's not a lot about hardlinks published out there. I think in that case, though, what would control would be who was the owner of the file; if you own a file, can I set permissions on it, if I've got a hardlink in my home directory? – tsc_chazz Mar 19 '21 at 17:42
-
what do you mean "not a lot about hard links published"? See e.g. What is the difference between symbolic and hard links? https://en.wikipedia.org/wiki/Hard_link https://unix.stackexchange.com/questions/tagged/hard-link?tab=Votes – ilkkachu Mar 19 '21 at 17:54
-
only the file owner can set the permissions on it. But others may be able to read it, if it's accessible to them through some path. – ilkkachu Mar 19 '21 at 17:55
-
Man pages seem to spend a lot more time on how symlinks are handled than hardlinks. But no matter... seems to me that the OP's question is now answered. If it's a symlink, chmod will not change it; if it's a hardlink, it will only get changed if he owns the file. And yeah, I'll shut up now. – tsc_chazz Mar 19 '21 at 18:04
/home/<user>/
- no further access possible – Mr R Mar 18 '21 at 21:47