CentOS/Plesk 上所有 vhosts httpdocs 目录的递归 chmod

CentOS/Plesk 上所有 vhosts httpdocs 目录的递归 chmod

运行 CentOS 7.8 和 Plesk 的共享网络托管服务器具有数百个虚拟主机的以下目录结构:

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

httpdocs 文件夹包含 Plesk 中的 Web 文件,类似于 Apache/cPanel 上的标准 public_html 目录。

我正在寻找一个命令或脚本,用于遍历每个 vhosts 域目录,并通过 SSH 递归地 chmod httpdocs 中的所有内容 - 将文件更改为 644,将文件夹更改为 755。/domain1.com/、/domain2.com/ 等内部还有其他目录,因此不应触碰它们,而应触碰 httpdocs 中的内容。

答案1

由于您需要更改的所有内容/var/www/vhosts/*/httpdocs/*,您可以遍历内部的目录并针对httpdocs 和文件和目录的/var/www/vhosts/每个项目执行。findchmod

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

答案2

据我了解,您想要恢复意外更改的文件/目录的权限。

然后您可以运行此命令来修复权限:

$ plesk repair fs -system -y

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

相关内容