I accidentally ran
chmod 777 * (without the
-R parameter) on my home directory.
Will It be a problem? Then how to solve it?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
If you ran just
chmod 777 * and not the evil
chmod -R 777 *, you haven't really done much bad to your system.
Notably, however, every top-level file and directory will need to be restored to their original permissions. Fortunately, this is a relatively simple operation. Simply run the below command:
chmod a=r,u+w,a+X *
This will do some fancy magic to reset all folder permissions back to 644 for files (the default) and 755 for folders (again, the default). See this Stack Overflow answer for a more detailed idea of how this command works.
From there, permissions should be reset to default. You may additionally need to change some other permissions back to what they were before, but this should (at the least) undo the damage.
Notably, you also want to run these two commands:
chmod 700 .ssh chmod 600 .Xauthority
This will prevent any authentication errors either relating to X11 or SSH due to mismatched permissions. While these shouldn't matter, it's better to be safe than sorry.
In all honesty, running
chmod on your home directory isn't the absolute worst thing in the world. While it can cause problems with things like SSH and
Xauthority, it's pretty far from "catastrophic" as you own all the files in your home dir, and (ideally) only you should have access to them.
Given this, it's perfectly safe (but not necessarily the best idea) to just be lazy here and deny access to your entire home-folder to users that are either not yourself or not root. You can do this by running the below command:
chmod 700 ~
Effectively, this will allow only your user to access your home folder. Other users (except for
root -- which has access to everything anyways) will have no way at all to access your home folder, and as such it doesn't really matter that everything inside is set to world-readable/writeable/executable.
If you just do this and call it a day, though, some systems (again) like Xauthority and SSH may complain, so pay heed to that. Similarly, some services that have a legitimate need to access your home folder under a different user account will also no longer be able to. You can somewhat solve this issue through advanced permissions-fu and ACLs, but that's just going down a very dark and windy rabbit-hole.