【问题标题】:Applying chmod 755 (or other) when ftping to apache var/www/ virtual host directories?ftping 到 apache var/www/ 虚拟主机目录时应用 chmod 755(或其他)?
【发布时间】:2015-06-18 08:16:46
【问题描述】:

我很难理解如何应用目录和文件权限,以便 ftp 用户通过 ftp 客户端创建的文件和目录可以浏览。换句话说,默认应用 755。

我在 Ubuntu 14.04.2 LTS、Trusty Tahr 和 vsftpd 服务器上运行 Apache 2。

我的目录结构如下。

var/www/
var/www/sites/
var/www/sites/master_demo/public_html
var/www/sites/test_site/public_html

我已经运行了以下

usermod -aG www-data test_user
chgrp -R www-data /var/www/sites/test_site/public_html/
chown -R test_site:www-data /var/www/sites/test_site/public_html/
chmod -R 755 /var/www/sites/test_site/public_html/

目录权限如下:

cd var/www/sites/
ls -l
dr-xrws--- 3 master_demo www-data 4096 Jun 17 14:00 master_demo
drwxr-xr-x 3 test_site   www-data 4096 Jun 16 13:32 test_site

cd var/www/sites/test_site/
ls -l
drwxr-xr-x 3 test_site www-data 4096 Jun 17 17:43 public_html

当 test_site 用户使用 ftp 添加文件时,这些是权限

-rw------- 1 test_site test_site  152 Jun 18 08:27 about.html
drwx------ 2 test_site test_site 4096 Jun 18 08:27 css
-rw------- 1 test_site test_site  152 Jun 18 08:27 index.html

如何让文件自动获得正确的权限,以便文件可浏览 (755)?我知道显而易见的答案可能是运行批处理文件,但这有必要吗?我不想每次都运行命令。

chmod -R 755 /var/www/sites/test_site/public_html/*
ls -l
-rwxr-xr-x 1 test_site test_site  152 Jun 18 08:27 about.html
drwxr-xr-x 2 test_site test_site 4096 Jun 18 08:27 css
-rwxr-xr-x 1 test_site test_site  152 Jun 18 08:27 index.html

我是 linux 新手,所以请温柔:)

我可以确认 test_site 用户在 www-data 组中

id test_site
uid=1004(test_site) gid=1005(test_site) groups=1005(test_site),33(www-data)

【问题讨论】:

    标签: linux apache chmod


    【解决方案1】:

    我想你要找的是umask

     umask 0022
     umask -p
     umask -S
    

    您需要修改您的默认/etc/profile 以使其永久化。 umask 0022将在创建时提供目录 chmod 755 和文件 chmod 644,这是 apache 中 www 文件夹的推荐权限。

    例子

    umask 0022
    mkdir www
    touch www/{index.html,style.css}
    drwxr-xr-x. 2 user user 4096 Jun 18 10:53 .
    drwxr-xr-x. 3 user user 4096 Jun 18 10:52 ..
    -rw-r--r--. 1 user user    0 Jun 18 10:53 index.html
    -rw-r--r--. 1 user user    0 Jun 18 10:53 style.css
    

    FTP 还支持在开始传输之前设置umask。使用 ftp 设置它,设置 if 仅用于该传输,这样您就不需要像使用 /etc/profile 那样在系统范围内更改它。

    【讨论】:

    • 很高兴我能帮上忙 :)
    • 感谢您的抢先回复。从您的回答中,我发现我需要在 /etc/vsftpd.conf 中设置/取消注释 umask 设置:“local_umask=022”。它需要重启 vsftpd 服务:“service vsftpd restart”。 ftp 用户必须重新连接 ftp 客户端。
    猜你喜欢
    • 2013-10-05
    • 2012-01-27
    • 2015-12-03
    • 2012-10-26
    • 2019-11-14
    • 1970-01-01
    • 2018-12-06
    • 2013-01-29
    • 1970-01-01
    相关资源
    最近更新 更多