伙计们,我有一个Linux专用服务器。
有多个用户在服务器上pipe理特定的目录。
但是,如果用户上传的东西,例如一个插件/库。 当它被执行时,它会创build该插件所需的子目录。 用户没有该目录的权限。
如何自动把775权限给所有目录?
接收上传的服务器的umask必须设置为002 ,然后新创build的目录将获得775权限。
find /path/to/base/dir -type d -exec chmod -R 755 {} +;
将recursion地更改文件夹的权限。 您可以设置一个cron作业来自动执行此操作,或者根据需要从插件根目录中简单执行。
添加用户到Apache / PHP组
usermod -g组的用户名
留意上传的文件
/usr/bin/inotifywait -e create -e attrib \ -mrq /home/project/public_html/plugins | while read file; do echo -n "$file " >> /var/log/uploads_monitor.log echo `date | cut -d " " -f1-4` >> /var/log/uploads_monitor.log chmod 775 $file >/dev/null 2>&1 done
您可能需要考虑使用file system access control lists (setfacl command) 。 这样你的改变只会影响你想改变的目录,并且不会对整个系统产生不希望的影响,比如说你改变了umask的值。
例如,如果你的用户属于一个特定的组,你可以给这个组在父目录及其后代上使用'rwx'。 这样,任何创build的文件或目录都会自动为属于该组的任何用户设置“rwx”。
setfacl -R -mg:groupname:rwx / shareddirectory setfacl -d -mg:groupname:rwx / shareddirectory
您可以自定义此以适应您的scheme。 我的要点是setfacl可能有你需要的选项。
我build议你看看ruid2 ( 预build的软件包 ),它允许一个域的所有HTTP请求作为该域的所有者而不是Apache用户运行。 其中一个抱怨就是FastCGI无法正常运行 。
这就是我在CentOS 6 x86_64服务器上加载它的方法:
/root rpm -Uvh atomic-release*rpm yum install mod_ruid2 这将导致您的操作系统上的这些文件:
/etc/httpd/conf.d/ruid2.conf /usr/lib64/httpd/modules/mod_ruid2.so /usr/share/doc/mod_ruid2-0.9.1/ /usr/share/doc/mod_ruid2-0.9.1/LICENSE /usr/share/doc/mod_ruid2-0.9.1/README 安装mod_ruid2-0.9.6-3.el6.art.x86_64(或当前版本)后,运行命令`apachectl -t -D DUMP_MODULES`
寻找这样的结果:
Loaded Modules: core_module (static) mpm_prefork_module (static) http_module (static) so_module (static) auth_basic_module (shared) auth_digest_module (shared) authn_file_module (shared) authn_alias_module (shared) authn_anon_module (shared) authn_dbm_module (shared) authn_default_module (shared) authz_host_module (shared) authz_user_module (shared) authz_owner_module (shared) authz_groupfile_module (shared) authz_dbm_module (shared) authz_default_module (shared) ldap_module (shared) authnz_ldap_module (shared) include_module (shared) log_config_module (shared) logio_module (shared) env_module (shared) ext_filter_module (shared) mime_magic_module (shared) expires_module (shared) deflate_module (shared) headers_module (shared) usertrack_module (shared) setenvif_module (shared) mime_module (shared) dav_module (shared) status_module (shared) autoindex_module (shared) info_module (shared) dav_fs_module (shared) vhost_alias_module (shared) negotiation_module (shared) dir_module (shared) actions_module (shared) speling_module (shared) userdir_module (shared) alias_module (shared) substitute_module (shared) rewrite_module (shared) proxy_module (shared) proxy_balancer_module (shared) proxy_ftp_module (shared) proxy_http_module (shared) proxy_ajp_module (shared) proxy_connect_module (shared) cache_module (shared) suexec_module (shared) disk_cache_module (shared) cgi_module (shared) version_module (shared) fcgid_module (shared) perl_module (shared) php5_module (shared) python_module (shared) ruid2_module (shared) ssl_module (shared)
如果它在那里,你很好走。
接下来,对ruid2.conf文件进行必要的添加。
请注意,由于Plesk使用/var/www/vhosts/mydomain.com/httpdocspath设置了我的主帐号,所以我首先添加了这个:
<Directory /var/www/vhosts/mydomain.com/httpdocs> RMode stat RUidGid apache apache RGroups apache psaserv </Directory>
然后,它使用/var/www/vhosts/mydomain.com/myotherdomain.compath设置其他域网站,所以我为每个人添加了这个:
<Directory /var/www/vhosts/mydomain.com/myotherdomain.com> RMode stat RUidGid apache apache RGroups apache psaserv </Directory>