The last time I wrote about this, I was a VestaCP user. I’ve since upgraded my VPS to CyberPanel, which I’ll discuss in a future post. Either way, I *STILL* work on my websites as a root user on my VPS. When I copy over WordPress or other files they retain root ownership. I made this simple shell script to run to set permissions quickly on all files of all users. CyberPanel actually has an option to fix permissions in the web UI, but I’m a CLI guy.

I’m certainly not a bash pro, but here you go …

echo
echo
echo Setting ownership on users\’ web folders …
echo
for dir in /home/*; do
userv=$(stat -c ‘%U’ $dir)
groupv=$(stat -c ‘%G’ $dir)
dir=$(echo $dir | cut -c 7-)
if [ “$dir” == ‘cyberpanel’ ] || [ “$dir” == ‘backup’ ] || [ “$dir” == ‘vmail’ ]
then
:
else
echo “$dir”
chown -R “$userv”:”$groupv” /home/”$dir”/public_html/
fi
done
echo
echo Done!
echo