Web服务器用户和组

我已经build立了一个Web服务器,它将托pipe多个客户端的站点,每个客户端将拥有自己的用户,他们的网站文件将存在于/var/www

我们通过名为DeployHQ的服务来部署代码,通过使用客户端用户名的SSH进行连接,因此当文件被推送到服务器时,会使用该客户端的用户名和组来创build它们。

我遇到的问题是Web服务器用户www-data无法更新文件,例如.htaccess文件:

  4 -rw-rw-r-- 1 client_user client_user 945 Oct 30 12:07 .htaccess 

我可以将文件组更改为www-data ,但是不会以这种方式创build部署的新文件,因此这不是一个长期的解决scheme。

考虑到我想为每个客户端的用户,任何人都可以推荐一种方法来允许www-data做客户端用户可以做的任何事情?

我刚刚读了一些关于设置Set-Group-ID ,我应该考虑一下吗?

非常感谢

这可以通过在每个用户的目录上设置SGID位来实现。 例如:

 tom@tomh:~▶ mkdir testdir # Just an example dir tom@tomh:~▶ sudo chgrp www-data testdir # Change the group tom@tomh:~▶ touch testdir/before tom@tomh:~▶ ls -la testdir/before # At the moment files have the default group 'tom' -rw-rw-r-- 1 tom tom 0 Nov 5 11:04 testdir/before tom@tomh:~▶ sudo chmod g+s testdir/ # Set the SGID bit on the dir tom@tomh:~▶ touch testdir/after tom@tomh:~▶ ls -la testdir/after # Files now have the same group as the dir -rw-rw-r-- 1 tom www-data 0 Nov 5 11:04 testdir/after 

记住要确保你的umasks为用户提供正确的组权限的文件呢!