Mic*_*ith 5 ubuntu permissions user-management
我正在设置一个 Ubuntu 服务器,它将有 3 或 4 个 VirtualHosts,我希望用户能够在其中工作(添加新文件、编辑旧文件等)。我目前计划将网站存储在其中,/var/www
但不反对移动它。
我知道如何添加新用户,我知道如何添加新组。我不确定处理只能编辑某些网站的用户的最佳方式。我阅读了这个问题中的答案,所以我想我可以设置一个组并将用户添加到该组中,但是他们都具有本质上相同的权限。我是否只需要为每个用户分配特定的权限?或者有更好的处理方法吗?
补充:我还应该注意,我将让每个用户通过 SSH/sFTP 登录。用户永远不需要在服务器上做任何其他事情。
您应该为每个网站使用一个组。并使所有需要写访问权限的用户成为相应组的成员。
groupadd site1_com
mkdir /var/www/www.site1.com
chgrp site1_com /var/www/www.site1.com
find /var/www/www.site1.com -type d -print0|xargs -0 chmod g=rwxs
chmod -R g+rw /var/www/www.site1.com
usermod -aG site1_com user1
Run Code Online (Sandbox Code Playgroud)
现在,每次用户在 /var/www/www.site1.com 文件夹下创建文件时,他们应该使用umask 0002
(在 ~/.bashrc 或部署脚本中)或者他们应该为该组设置权限以具有读写访问权限chmod -R g+rw /var/www/www.site1.com 2>/dev/null
.
设置权限的另一种解决方案是使用 dnotify。/usr/local/sbin/dnotify_handler-reset_perms.sh
使用以下内容创建脚本:
#! /bin/sh
CHANGED_FOLDER=$1
find $CHANGED_FOLDER -maxdepth 1 -mmin 0 -not -perm -g+w -exec chmod g+w {} \;
Run Code Online (Sandbox Code Playgroud)
并添加到/etc/rc.local
:
dnotify --recursive /var/www/www.site1.com --create --execute --background /usr/local/sbin/dnotify_handler-reset_perms.sh
Run Code Online (Sandbox Code Playgroud)