0

I managed to messed up server permissions on entire server

chown root:root -R /
chmod 777 -R /

How to fix it? I can't login as root using terminal on that machine it show error "Invalid password" and SSH shows error "connection reset by remote server"

Note: I try to reinstall CentOS 7 using USB. but got stuck during Select disk stage as it will not let me select / without formating it. This question explains what my commands did. Why is "chmod -R 777 /" destructive?

Faraz
  • 183
  • 1
  • 2
  • 10

2 Answers2

4

Restore from backup or rebuild the server.

Safado
  • 4,836
4

I managed to Solve it, here are the steps i followed.

To fix the issue of root login using terminal.

  1. boot using bootable USB/CD
  2. select recover and mound disk
  3. go to mounted folder and run chown root -R / and chmod 755 -R /
  4. chmod 0700 -R /root/.ssh
  5. reboot normally
  6. Ignore SElinux contexts warnings and let it re-store contexts

After this you will be able to login to machine using root

To fix file permission and owners info use these commands rpm --setperms {packagename} and rpm --setugids {packagename}

To fix you all system just rum them in loop more details here

for p in $(rpm -qa); do rpm --setperms $p; done
for p in $(rpm -qa); do rpm --setugids $p; done

It will fix permissions for most of packages.

If you can't login using SSH follow these steps

  1. systemctl restart sshd It will fail
  2. systemctl status sshd It will show you the file with wrong permissions
  3. Fix the file permission using chmod 0700 -R /root/.ssh OR chmod 0700 your_file_path
  4. repeat this process until SSH service start successfully

Using these steps I managed to restore all essential services on my server.

Finally to restore default permissions for vhosts created using Plesk. I use this command as described on plesk website

# /usr/local/psa/bin/repair --restore-vhosts-permissions
Faraz
  • 183
  • 1
  • 2
  • 10