简体   繁体   English

在 ftping 到 apache var/www/ 虚拟主机目录时应用 chmod 755(或其他)?

[英]Applying chmod 755 (or other) when ftping to apache var/www/ virtual host directories?

I'm struggling to understand how to apply directory and file permissions so that files and directories created by the ftp user, via an ftp client, are browsable.我正在努力理解如何应用目录和文件权限,以便 ftp 用户通过 ftp 客户端创建的文件和目录可以浏览。 In other words 755 is applied by default.换句话说,默认情况下应用 755。

I'm running Apache 2 on Ubuntu 14.04.2 LTS, Trusty Tahr, with vsftpd server.我在 Ubuntu 14.04.2 LTS、Trusty Tahr 和 vsftpd 服务器上运行 Apache 2。

My directory structure is as follows.我的目录结构如下。

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

I've run the following我已经运行了以下

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/

Permissions on the directories are as follows:目录权限如下:

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

When a file is added using ftp by the test_site user these are the permissions当 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

How do I get the file to automatically be given the correct permissions so the files are browsable (755)?如何让文件自动获得正确的权限,以便文件可浏览 (755)? I know the obvious answer might be to run a batch file, but is that necessary?我知道显而易见的答案可能是运行批处理文件,但这有必要吗? I don't want to have to run the command everytime.我不想每次都运行命令。

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

I'm new to linux so please be gentle :)我是 linux 新手,所以请保持温和:)

I can confirm that test_site users is in the www-data group我可以确认 test_site 用户在 www-data 组中

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

I think what you are looking for is umask我想你要找的是umask

 umask 0022
 umask -p
 umask -S

You will need to modify your default /etc/profile in order to make this permanent.您需要修改默认的/etc/profile以使其永久化。 umask 0022 will on creation give directories chmod 755 and files chmod 644 which is the recommended permissions for the www folder in apache. umask 0022将在创建时提供目录chmod 755和文件chmod 644 ,这是 apache 中www文件夹的推荐权限。

Example例子

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 also supports setting umask before initiating a transfer. FTP 还支持在启动传输之前设置umask Setting it with ftp, sets if for that transfer only, so that you don't need to change it system-wide as you would with /etc/profile .使用 ftp 设置它,只为该传输设置 if,这样您就不需要像使用/etc/profile那样在系统范围内更改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM