首页 文章

在.bash_profile中创建别名以获取Wordpress上的正确权限

提问于
浏览
1

所以我一直在阅读关于Wordpress正确权限的各种帖子,最值得注意的是:

[1] [1]:Correct file permissions for WordPress

[1] [1]:https://codex.wordpress.org/Hardening_WordPress

有人可以解释是否将我的用户添加到www-data组中是个好主意 . 为什么我需要这样做,因为我不完全理解这一点,我是否需要这样做......

我花了很多时间更新我所有的wordpress网站,并开始在更高的层次上保护它们 . 我想创建一个命令或脚本,以便我可以快速设置正确的权限

  • 设置wordpress

  • 更新插件和wordpress

  • 普通强化Wordpress,用户仍然可以编辑和上传媒体,但它已被安全锁定 .

因此,最好在.bash_profile中创建.sh文件或创建别名 . 我有大约14个wordpress网站,我刚刚花时间更新和保护现在我需要整理权限 . 显然,我希望以最有效的方式做到这一点 .

到目前为止,.bash_profile选项是:

Setting up Wordpress and Updating

alias suwpchn='sudo chown -R www-data:www-data *; find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; ls -la;'

但我得到的错误是

find:paths必须在表达式之前:find

但是我也在考虑使用bash脚本来调用它,它会立即设置所有的WordPress网站权限,这是我从Michael Conigliaro那里找到的:

#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro (https://gist.github.com/macbleser/9136424)
#
WP_ROOT=${1:-.} # <-- wordpress root directory, current directory by default
[ -e "$WP_ROOT/wp-config.php" ] || { echo "Usage: $0 /path/to/wordpress"; exit; } # <-- detect that the directory is a wordpress root
WP_OWNER=$(id -u $(logname)) # <-- wordpress owner (This assumes the wordpress owner is the logged in user)
WP_GROUP=$(id -g $(logname)) # <-- wordpress group (This assumes the wordpress owner is the logged in user)
WS_GROUP=$(
     source /etc/apache2/envvars 2>/dev/null && # This works on debian-based systems at least
     echo "$APACHE_RUN_GROUP" ||
     echo nobody  
) # <-- webserver group
echo "Fixing permissions on $WP_ROOT"
echo "Wordpress owner.group: $WP_OWNER.$WP_GROUP"
echo "Web Server group: $WS_GROUP"

echo 'reset to safe defaults'
find ${WP_ROOT} -exec chown ${WP_OWNER}:${WP_GROUP} {} \;
find ${WP_ROOT} -type d -exec chmod 755 {} \;
find ${WP_ROOT} -type f -exec chmod 644 {} \;

echo 'allow wordpress to manage wp-config.php (but prevent world access)'
chgrp ${WS_GROUP} ${WP_ROOT}/wp-config.php
chmod 660 ${WP_ROOT}/wp-config.php

echo 'allow wordpress to manage .htaccess'
touch ${WP_ROOT}/.htaccess
chgrp ${WS_GROUP} ${WP_ROOT}/.htaccess
chmod 664 ${WP_ROOT}/.htaccess

echo 'allow wordpress to manage wp-content'
find ${WP_ROOT}/wp-content -exec chgrp ${WS_GROUP} {} \;
find ${WP_ROOT}/wp-content -type d -exec chmod 775 {} \;
find ${WP_ROOT}/wp-content -type f -exec chmod 664 {} \;

当我运行这个脚本时,我的wordpress网站会出现白屏 . 我正在使用Debian GNU / Linux 8 \ n \ l

我看到的WS_GROUP是错误的,因为它打印出来,因为apache在我的服务器上运行为www-data . 但我不确定如何修复它,因为在源/ etc / apache2 / envvars中它说导出APACHE_RUN_GROUP = www-data所以不确定为什么那部分不起作用 .

任何人都可以帮助我,看看如何修复脚本,以及如何添加wordpress网站数组,以便我可以运行脚本,它将设置所有网站的权限,以便我可以自动更新网站...

谢谢J

1 回答

  • 1

    它看起来像';'因为它被转义而没有被识别,但-exec仍然需要它,所以你可以使用它们:

    alias suwpchn='find . -type d -exec chmod 755 {} \;; find . -type f -exec chmod 644 {} \;; ls -la;
    

    我不是一个重击大师,所以我不能在这里详述 .

相关问题