Recover from a mistaken chown dude:friends / name_of_folder -R

Systems covered:

  1. Linux with grub
  2. Ubuntu
  3. Debian
  4. SLES
  5. CentOS
  6. RedHat

These systems should be fairly similar in grub options.

I accidentally executed the following command as sudo (I pannick!)

chown dude:friends / name_of_folder -R

At this point, sudo no longer works, I don't have a root password, cannot call and wake people up to fix this, so we made a vmware snapshot, went to the vmhost, found grub through the vmware web console.

web services stop working, can no longer ssh into the server for new connections.

 

the point is that I added a space between / and name_of_folder my fault, I stopped the command after 1-2 seconds, how can I recover from that

GREAT SOLUTION:

Use grub to put yourself into single user mode as root without requiring the root password

Reboot your server, hold the 'shift' key until you see the grub menu, it comes fast so pay attention.  Then hit the 'e' key for 'edit', find the line of the configuration called linux, at the end of the linux line add the following string:

rw init=/bin/bash

In sles 12 sp4 the command ctrl-X allows you to boot the system with the indicated parameters.  The instructions should be obvious otherwise a web search engine is your best friend.

Then:

chown root:root / -R;

chmod u+s /usr/bin/sudo;

then review your /home folders, set the ownership correctly there such as

chown username:users /home/username -R

works best if you can compare folder ownerships to a working server but this at least should give you the ability to figure it out (worked for me).

reboot after this is done, should be in far better shape