在.bash_配置文件中创建别名以获取对Wordpress的正确权限

在.bash_配置文件中创建别名以获取对Wordpress的正确权限,wordpress,bash,apache,chmod,.bash-profile,Wordpress,Bash,Apache,Chmod,.bash Profile,因此,我一直在阅读关于Wordpress正确权限的各种帖子,最显著的是: [1] [1]: [1] [1]: 有人能解释一下将我的用户添加到www数据组是否是个好主意吗。为什么我需要这样做,因为我不完全理解,我需要这样做 我刚刚花了大量时间更新我所有的wordpress网站,并开始在更高级别上保护它们。我想创建一个命令或脚本,以便快速设置两个命令之间的正确权限 建立wordpress 更新插件和wordpress 普通加固Wordpress,用户仍然可以编辑和上传媒体,但它被安全锁定 因此,最好

因此,我一直在阅读关于Wordpress正确权限的各种帖子,最显著的是:

[1] [1]:

[1] [1]:

有人能解释一下将我的用户添加到www数据组是否是个好主意吗。为什么我需要这样做,因为我不完全理解,我需要这样做

我刚刚花了大量时间更新我所有的wordpress网站,并开始在更高级别上保护它们。我想创建一个命令或脚本,以便快速设置两个命令之间的正确权限

  • 建立wordpress
  • 更新插件和wordpress
  • 普通加固Wordpress,用户仍然可以编辑和上传媒体,但它被安全锁定
  • 因此,最好创建一个.sh文件或在.bash_配置文件中创建一个别名。我有大约14个wordpress网站,我刚刚花时间更新和保护,现在我需要整理权限。显然,我希望以最有效的方式来做这件事

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

    设置Wordpress并更新

    alias suwpchn='sudo chown -R www-data:www-data *; find . -type d -exec chmod 755 {} \; find . -type f -exec chmod 644 {} \; ls -la;'
    
    但我得到的错误是

    查找:路径必须位于表达式:查找之前

    但我也在考虑使用一个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 {} \;
    
    #/bin/bash
    #
    #此脚本根据建议配置WordPress文件权限
    #从http://codex.wordpress.org/Hardening_WordPress#File_permissions
    #
    #作者:迈克尔·科尼利亚罗(https://gist.github.com/macbleser/9136424)
    #
    
    WP_ROOT=${1:-.}#它看起来像“;”由于已转义,因此未被识别,但-exec仍需要它,因此您可以同时使用:

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

    我不是bash大师,因此无法在此详细说明。

    谢谢您的提醒。这就是我到目前为止所做的<代码>别名hwp='sudo查找-类型d-execchmod-r775{}\;;sudo find-f型-exec chmod 644{};;sudo chown管理员:www data-R wp content/*;sudo chmod 400 wp-config.php.htaccess;'