Home » articles » 26 May 2018 » 34 supporters » No Comment »

Steps to recover wrong permission in Centos 7 Cpanel

26 May 2018 34 supporters No Comment

Cpanel logoRecently we have permission issue with one of our server. Not sure what cause the change but all the files and folders permission are wrong.

Luckily we found the way on how to recover the server 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

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.