Okay, we need to clean up the mess made of your system first. You'll need to boot into recovery mode first, because you need root for this.
Fix /usr/bin
First off, we need to fix your binaries. Run the below command to repair all binaries and let root
re-take ownership:
chown -R root /usr/bin
Fix setuid
binaries
Now that /usr/bin
is fixed, we can focus on all the binaries that lost their setuid
status. The setuid
flag is a special executable flag that allows for an executable to run as the owning user, as opposed to the calling user. Run the below commands to fix this:
chmod u+s chfn chsh gpasswd newgrp passwd pkexec sudo
Fix /usr/lib
Similarly to step 1, we need to reassign everything in /usr/lib
to the root user.
chown -R root /usr/lib
Fix /usr/share
This one is a much more involved process because things in /usr/share
could (possibly) be owned by non-root users. For now, you're going to have to restore all permissions to root
, and then fix any problems that come up as they come up. Be sure to watch your log files for any permission errors or the like.
chown -R root /usr/share
Reboot and Pray
Running commands like chown
and chmod
recursively on system folders without knowing exactly what you're doing is very dangerous. While it is occasionally possible to recover from a mess like this, it's not always possible. You (fortunately) only really reverted folders where everything is owned by root
, so fixing problems is pretty simple. But, it is important to know that this could have ended with you being forced to reinstall your entire system. You've also dodged a bullet by not overwriting groups -- that could have very easily been catastrophic.
Don't mess around with chown
/chmod
, and if you're using those commands with sudo
, you're probably doing something wrong. Double- and triple-check what you're doing and make sure what you want to do is sane. Also make sure your commands are free of typos.
Also be sure you're not getting into the habit of prefixing everything that doesn't work with sudo
-- this is a one-step method to destroying a Linux install because of carelessness.
chown -R root usr/{lib/node_modules,bin,share}
– Rahul Jan 22 '17 at 04:13