How can I revert a chmod on the etc directory?

One thing went wrong: the use of sudo with that command. The -R switch tells chmod to recursively set the permissions to that directory, which is, in every case, a non-recommended action (should we call it: heresy) if you don't know what are you doing (once this happened to me, I didn't issue the command but a faulty GUI made it, and my system went wire).

It was only file permissions. Then why does the whole system seems completely blown up?

GNU/Linux is very sensitive to file permissions, as it was built with stability and security in mind. Same applies to most programs run in GNU/Linux (i.e. apache2 drops root privileges and uses www-data, or similar user, and your 700 permission wouldn't allow it to read/write it own files).

Why is it that no login passwords are working now?

As you already mention, login passwords are stored in a file in /etc/passwd and only root (I assume you didn't change that) can read it, but the login prompt (or GUI login) uses a non-privilege account, hence it cannot read the file.

But how did changing permissions jeopardize everything?

Same as said above, Linux is very sensitive to file permissions. Some programs even check the permissions of their configuration files and if they are not expected they won't run at all.

How can I revert my etc directory to its earlier state?

If you use a RPM-based distro, this can be done using the rpm --setperms command, it would be painfully reverting one by one the packages, on Debian-like system apt-get --reinstall install is your friend. Other solutions may be available, but would need a working system for it.


Let's see, what you have done is set permissions in the whole /etc dir as read/write/execute allowed only for the owner of the file/dir, denied for everybody else. If you are confused by the file permissions, you can read more at Wikipedia: Traditional UNIX permissions.

The reason you have blown up your system is because many processes can't read their settings anymore, being unable to access /etc. It won't be easy to recover the entire /etc dir to its previous state. How to do that will depend on your distro, but basically it means reinstalling every package which holds any file within /etc.

As a quick band aid to be able to use the system, in order to fix it properly (reinstalling all the packages with contents within /etc, as stated above), you could do:

    # sudo find /etc -type d -exec chmod 775 '{}' \;
    # sudo find /etc -type f -exec chmod 664 '{}' \;

With those two lines you'll be setting liberal permissions in all the /etc dir, with read/write allowed for the owner and the group, and read allowed for everybody else. The reason of the two chmod is to set the execute bit only on dirs. Some processes will complain or fail even so, including any executable within /etc, but you should be able to do the reinstall I outlined above.

Please be aware than until you recover the original permissions your system will be, at the very least, in an insecure state.

Tags:

Linux

Chmod

Files