Ubuntu: Is `sudo chown -R $USER $HOME` safe?



Question:

Are there any files, like in ~/.config or elsewhere, in the home directory that should be owned by root?

Will recursively changing the ownership of every file in my user's ~ to be my user be harmful?


Solution:1

Are there any files, like in ~/.config or elsewhere, in the home directory that should be owned by root?

No you should be the owner of all the files and folders under your home.

What may be the possible trouble otherwise?

In your home there exists many user level settings for various applications and system itself in the hidden files and folders. If you chown them to root you will be in trouble in the next login. At the time of login your profile could not be loaded as you have no longer access permission to the configuration files. And you will be most probably kicked out to the login screen. In the process you will lock yourself.

Will recursively changing the ownership of every file in my user's ~ to be my user be harmful?

There is no harm in doing so. But keep in mind the case as pointed out by Lekensteyn in the comment above. I am quoting it,

Beware of rare edge cases when literally executing the command in the title, $USER and $HOME can be changed. E.g. USER=nobody; HOME=/; sudo chown -R $USER $HOME is unsafe.

There is a better proposal than to recursive chown in the comment above,

you can find files not owned by you using find ~ ! -user $USER -ls (assuming a same environment where the variables have not been changed). And rename only those files.


Solution:2

All of the files and directories in your home directory(/home/user) should be owned by your user.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »