0

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?

3
  • Change the permission on the directory - /home/<user>/ - no further access possible
    – Mr R
    Mar 18, 2021 at 21:47
  • Normally, the directories in /home only have permissions set for the owner. This shouldn't be necessary unless something was done to change them. Mar 18, 2021 at 21:49
  • @AnswerMyQuestion, do you have some particular use-case as to why you'd have files with names inside someone's $HOME and outside it? And, just to make clear, I suppose you mean files hard linked in and out of the home directory, and not just symlinks?
    – ilkkachu
    Mar 19, 2021 at 17:52

1 Answer 1

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.

5
  • 3
    think hard links
    – ilkkachu
    Mar 19, 2021 at 10:10
  • 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, 2021 at 17:42
  • 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, 2021 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, 2021 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.