Despite other answers (or comments) say you are doomed, there is a good chance you can recover your system if you are able to boot from an external device. It will actually depend on some factors like if your installed system is encrypted, if your system is configured to allow external drives boot and similar issues. If this isn't the case, although this will be cumbersome and require hard work, you still have hope.
I use to have a couple of recovery functional bootable USB drives around, but even if you don't have one, you can create or even download a bootable Linux image from the internet (recommend a reliable source like your Linux distribution official home page).
At this point, after booting with the external drive, you can mount your internal "damaged" root system on /tmp/myroot:
# mkdir /tmp/myroot
# mount /dev/[whatever device is your internal root] /tmp/myroot
Then you should be able to chown the most important executables on /tmp/myroot/bin
and /tmp/myroot/usr/bin
. This will be a somewhat long list, but you would need at least /tmp/myroot/bin/sh
, /tmp/myroot/bin/login
, /tmp/myroot/bin/rpm
, /tmp/myroot/bin/chown
itself and probably a few others. The lazy approach is to temporarily move them and copy your external recovery directories to the internal system being recovered:
# mv /tmp/myroot/bin /tmp/myroot/damaged-bin
# mv /tmp/myroot/usr/bin /tmp/myroot/usr/damaged-usrbin
# cp -a /bin /tmp/myroot/bin
# cp -a /usr/bin /tmp/myroot/usr/bin
This will also involve other changes like recovering the ownership of /var
(currently mounted as /tmp/myroot/var
) and other directories. Again, the list may be long.
After doing this, you will have a minimally bootable system (as single user) and, after booting again, considering you are using a rpm based distribution, you can use rpm --setugids -a
to recover all system files ownerships (you will have to manually set the ownership of files on your home, etc...).
This answer is intended to provide the general idea of an approach that should work to recover your system. All the detailed steps probably require more directories and files to be adjusted before being able to boot the internal system in single user mode.
PS: Recovering from a backup would certainly be the best approach, and this is lessons learned. Even after recovering it manually, this will be like a refurbished car, it will never be the same...
Wish you good luck!
SUID
andSGID
bits, etc. (once you figure out what they should be), but a reinstall will be quicker. Much quicker. You should also readman chown
before yousudo chown
. – waltinator Jul 28 '23 at 21:51/home
is a seperate disk partition, you can tell the installer to put/home
on the same partition, AND Uncheck the "Format" checkbox. Do NOT format/home
. Otherwise, buy a big USB key, reformat toext4
(boot your install disk in "Try Ubuntu" mode, or download a Live USB, and try to copy all of$USER
's files, plus any application data you want to keep to the big USB key. Then, plan your reinstall, do your reinstall, reinstall your other applications, them copy stuff from the big USB key to your shiny, new system. Be prepared to struggle to get everything to integrate/work. – waltinator Jul 29 '23 at 03:25