我使用 CFT 创建了一个 apache 网络服务器;这是使用 RHEL 7。为了允许 ec2-user 修改 apache 文档根文件夹中的文件,我在 CFT 中添加了以下内容(取自 var/log/cloud-init.log)
Jun 30 16:11:15 ip-10-205-0-135 cloud-init: groupadd www Jun 30 16:11:16 ip-10-205-0-135 cloud-init: usermod -a -G www ec2-user Jun 30 16:11:16 ip-10-205-0-135 cloud-init: chown -R root:www /var/www Jun 30 16:11:16 ip-10-205-0-135 cloud-init: chmod 2775 /var/www Jun 30 16:11:16 ip-10-205-0-135 cloud-init: find /var/www -type d -exec chmod 2775 {} \; Jun 30 16:11:16 ip-10-205-0-135 cloud-init: find /var/www -type f -exec chmod 0664 {} \;
正如您从日志中看到的那样,一切顺利。但是,在ec2下登录时,出现如下权限错误:
[ec2-user@ip-10-206-32-92 html]$ aws s3 sync s3://gfrepo/releases releases download failed: s3://gfrepo/releases/binaries.html to releases/binaries.html [Errno 13] Permission denied: u'/var/www/html/releases/binaries.html' download failed: s3://gfrepo/releases/B1556013/B1556013.jar to releases/B1556013/B1556013.jar Could not create directory /var/www/html/releases/B1556013: [Errno 13] Permission denied: '/var/www/html/releases/B1556013'
我最终将我的权限提升为 sudo 以完成 s3 同步。不确定为什么它会为 ec2-user 提供权限错误。以下是权限列表:
[ec2-user@ip-10-206-32-92 www]$ ls -l total 0
drwxrwsr-x. 2 root www 6 Mar 21 02:33 cgi-bin
drwxrwsr-x. 3 root www 55 Jun 30 16:11 html
[ec2-user@ip-10-206-32-92 www]$ groups ec2-user
ec2-user : ec2-user adm wheel systemd-journal www
如您所见,ec2-user 是 www 组的一部分,而 www 是 html 子目录的所有者
最佳答案
您必须确保ec2-user
属于具有写权限的组
如果目录 /var/www/html
归 root 所有,它不会让您写入该文件夹。
首先在 /var/www/html
上执行 ls -l
找出组名是什么,它在用户旁边
然后发出这个命令
sudo usermod -a -G www ec2-user
您需要将ec2-user
添加到www
组
您已登录 ec2-user
,虽然您正在发出 aws s3 sync
命令,但您需要权限才能写入允许的目录,这就是为什么失败。
这个目录/var/www/html/releases/
没有权限。
Could not create directory /var/www/html/releases/B1556013 <----
或 su 到 root 并尝试命令。
关于linux - ec2-user 没有权限写入 web 文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38468015/