Securing cpanel website

Here we will learn easy command which will correct permission and ownership of all files and folders from cPanel account.

Below is command to correct ownership and permission of all files and folders of cPanel user. To execute this command you need root user access.

Suppose we are securing permission and ownership of cPanel user midnight. Then commands will be.

Correcting ownership of home directory

chown midnight.midnight /home/midnight

Command to set secure permission for home directory of cPanel user midnight

chown 711 /home/midnight

Following command will find all files and set secure permission as 644.

cd /home/midnight/public_html;find ./ -type f -exec chmod 644 "{}" \;

Now find all folders and set secure permission as 755

cd /home/midnight/public_html;find ./ -type d -exec chmod 755 "{}" \;

Above command will set 755 permission to public_html folder as well. But recommended permission for public_html folder is 750

cd /home/midnight/public_html;chmod 750 ../public_html

Now correcting ownership of all files and folders stored in public_html

cd /home/midnight/public_html;chown midnight.midnight ../public_html -R

Then correct ownership of public_html folder using command

cd /home/midnight/public_html;chown midnight.nobody ../public_html

You have set secure permissions and ownership to all files and folders for cPanel account midnight.