0

A shared web hosting server running CentOS 7.8 with Plesk has the following directory structure for a few hundred vhosts:

/var/www/vhosts/domain1.com/httpdocs/
/var/www/vhosts/domain2.com/httpdocs/
/var/www/vhosts/domain3.com/httpdocs/

httpdocs folder contains the web files in Plesk, like the standard public_html directory on Apache/cPanel.

I'm after a command or script to go through each vhosts domain directory and recursively chmod everything inside httpdocs - files to 644 and folders to 755 via SSH. There are other directories directly inside /domain1.com/, /domain2.com/ etc. so they shouldn't be touched, only the contents inside of httpdocs.

senectus
  • 103
  • 2

2 Answers2

1

Since you need to change all the contents of /var/www/vhosts/*/httpdocs/*, you could iterate over the directories inside the /var/www/vhosts/ and for each item execute find for the httpdocs and chmod for files and dirs.

for my_hosts in /var/www/vhosts/*/httpdocs; do

#DryRun to see the changes
find $my_hosts -type f -exec ls -l {}\;
find $my_hosts -type d -exec ls -ld {}\;

#Uncomment to make the change.
#find $my_hosts -type f -exec chmod 644 {}\;
#find $my_hosts -type d -exec chmod 755 {}\;
done
igiannak
  • 125
  • 6
  • 1
    Thanks! I had to add a space between the {} and \ at the end of the find, since I was getting "find: missing argument to `-exec'", but other than that it worked perfectly. It took something like an hour to run though, so I'm wondering if there's a more efficient way to do it. – senectus May 08 '20 at 08:58
0

From what I understand, you want to restore the permissions on the file / directory that accidentally changed.

Then you can run this to repair permission :

$ plesk repair fs -system -y

Reff : https://talk.plesk.com/threads/ruined-all-permissions-from-root.346168/

YonzLeon
  • 311
  • 1
  • 6
  • Thanks, but the plesk repair command only does chown to fix the owner/group for each vhost. It doesn't do chmod. I actually did this already since owners were also wrong for some files and directories, but a different solution for chmod is needed. – senectus May 08 '20 at 08:56