Wrong permission can cause headache to the system admin. Not sure what cause the change to our server but all the files and folders are wrong permission.
Luckily we found the way on how to recover the wrong permission issue without to format the server.
Just follow this steps.
1. Boot using boot USB/DVD
2. Select rescue and choose to mount the disk. The disk supposed to be mount as ‘/mnt/sysimage’
3. Go to mounted folder and run ‘chown root -R /mnt/sysimage’ and ‘chmod 755 -R /mnt/sysimage’ . It is similar like you ‘chmod 755 -R /’ in the real system.
4. chmod 0700 -R ‘/mnt/sysimage/root/.ssh’
5. Reboot the server. You should be able to remote the server now.
After that you need to fix permission for the system package. Run below command to fix permission.
for p in $(rpm -qa); do rpm --setperms $p; done for p in $(rpm -qa); do rpm --setugids $p; done
For the Cpanel hosting account, below command should be use;
for CPAccess in `ls -A /var/cpanel/users`; do chown -R $CPAccess:$CPAccess /home/$CPAccess; done for CPAccess in `ls -A /var/cpanel/users`; do chown -R $CPAccess:mail /home/$CPAccess/etc /home/$CPAccess/mail; done for CPAccess in `ls -A /var/cpanel/users`; do chown $CPAccess:nobody /home/$CPAccess/public_html; done
Next is to repair MySQL databases. Below command to restore MySQL database permission and ownership.
chmod 1777 /tmp chmod 751 /var/lib/mysql chown root:root /tmp chown -R mysql:mysql /var/lib/mysql
Next check the immutable attribute. Immutable attribute is used to prevent a file or directory from being modified and placing that attribute on MySQL data directory prevents it from working properly. To check immutable attribute;
lsattr /var/lib ----------I--e- /var/lib/mysql (good) ----i---------- /var/lib/mysql (bad)
To remove immutable attribute use command;
chattr -i /var/lib/mysql
Thank you for another informative blog. Where else could I get that type of information written in such a perfect way? I have a project that I’m just now working on, and I’ve been on the look out for such information.