Fixing the consequences of " chmod 777 /"

In ubuntu 14, 4 executed chmod 777 /, after which su and sudo -s stopped executing.

How do I fix this?

$ su 
operation not permitted

$ sudo -s
/etc/sudoers is world writable
no valid sudoers souces found, quitting
unable to initialize policy plugin
Author: aleksandr barakin, 2016-01-20

4 answers

The most effective way out of this situation, in my opinion, is to save the data files and reinstall the system.

The behavior of the two programs mentioned is just the tip of the" iceberg", the rest of the consequences will be revealed later, in the most likely unexpected moments. of the main "results" , we can note at least a couple: first, your system is now a "leaky sieve" (from the point of view of security and security of the system), and secondly, some "daemons" can either stop working at all (after a reboot), or work incorrectly.

I personally (considering myself far from a novice) would not even undertake to correct the consequences of such "vandalism" - it is a hellish painstaking work.

 11
Author: aleksandr barakin, 2016-01-20 13:41:53

You can also put the system on a neighboring virtual machine and make the automatic reduction of rights to one denominator with a simple script.

On a virtual machine:

find / |xargs stat -c "chmod %a %n" > /rights-1.txt # Создаёт файл где сохранены права и названия с путем 
find / |xargs stat -c "chown %U:%G %n" > /rights-2.txt # Создаёт файл с принадлежностями и путём

Transfer these files to the main system and simply execute:

bash </rights-1.txt 
bash </rights-2.txt
 3
Author: ArcherGodson, 2016-01-20 14:00:32

From under root

Chmod 440 /etc/sudoers

 2
Author: Hermann Zheboldov, 2016-01-20 13:15:24

The specified command could not cause such damage, apparently there was still a key -R.

You can reinstall all the installed packages, and the rights will be restored, except for files and directories that are not related to the packages. For systems with Debian package manager:

# apt-get --reinstall install `dpkg --get-selections | grep install | grep -v deinstall | cut -f1`

If it is not possible to reinstall some packages, you can skip them by adding the names to the filter:

# apt-get --reinstall install `dpkg --get-selections | grep install | grep -v deinstall | cut -f1 | egrep -v '(package1|package2)'`

A source: http://hyperlogos.org/page/Restoring-Permissions-Debian-System

If you can't log in as root, you'll have to boot from the flash drive. and make chroot on the partition with the corrupted system.

 1
Author: sercxjo, 2016-01-22 10:50:11