VPS/WHM/cPanel permissions problem

ridike

Registered
Dec 10, 2013
1
0
1
cPanel Access Level
Reseller Owner
Hi,

Can anybody help me with a permissions problem on a VPS? Whenever I create a cPanel account and log in to FTP/SFTP to the new account, I don't have permissions to edit the files or to do different things with them. I have to login with the root user or to give 777 to the whole folder of the cPanel's account in order to be able to edit the files with the cPanel account.
For example I upload a CMS package, unzip and install it but I can't because I don't have permissions to the folders/files, I have to log in with root to give the correct permissions. The same is when I install something with Softaculous, I can't edit the files afterwards, only with root user.

Somebody told be something about the usergroups are not correctly set up. I couldn't find a solution on google, hopefully I can find here.

Thank you very much!
 

chrisbuk

Well-Known Member
PartnerNOC
Dec 7, 2003
394
0
166
Liverpool, United Kingdom
cPanel Access Level
DataCenter Provider
Twitter
Hi

SSH to your server to / directory

type: nano fixperms.sh

paste:
#!/bin/bash
if [ "$#" -lt "1" ];then
echo "Must specify user"
exit;
fi

[email protected]

for user in $USER
do

HOMEDIR=$(grep $user /etc/passwd | cut -d: -f6)

if [ ! -f /var/cpanel/users/$user ]; then
echo "$user user file missing, likely an invalid user"

elif [ "$HOMEDIR" == "" ];then
echo "Couldn't determine home directory for $user"


else

echo "Setting ownership for user $user"

chown -R $user:$user $HOMEDIR
chmod 711 $HOMEDIR
chown $user:nobody $HOMEDIR/public_html $HOMEDIR/.htpasswds
chown $user:mail $HOMEDIR/etc $HOMEDIR/etc/*/shadow $HOMEDIR/etc/*/passwd

echo "Setting permissions for user $USER"

find $HOMEDIR -type f -exec chmod 644 {} \; -print
find $HOMEDIR -type d -exec chmod 755 {} \; -print
find $HOMEDIR -type d -name cgi-bin -exec chmod 755 {} \; -print
find $HOMEDIR -type f \( -name "*.pl" -o -name "*.perl" \) -exec chmod 755 {} \; -print
fi
done
then control+X to close, and Y to save.

then whenever you have permissions problems just ssh to server and type:

sh fixperms.sh USERNAME (replace USERNAME with the username of the Cpanel user with the issue)

this will fix the permissions of the users account.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,913
2,203
363
Hello :)

Please keep in mind that it's not always a good idea to change ownership of all your home directory files to the account username. Some files may have ownership set to another value on purpose. Instead, access your server via SSH as root, and check the ownership values on the following directories and files within them:

/home/$username

Are any of these files owned by "root"?

Thank you.
 

pagchen

Member
Aug 19, 2007
8
0
51
BEWARE!
This script will change the file permissions of files like .htpasswds in /home/username/ to less secure 0655.
I think it would be better if the last "find" commands run only in $HOMEDIR/public_html folder.
Even then as stated by CpanelMichael, it can put files that needs more secure permissions to less secure permissions inside the public_html folder.