我想在我所属的员工组所拥有的目录中创建一个文件。为什么我不这样做?
bmccann@bmccann-htpc:~$ ls -l /usr/local/lib/R/
total 4
drwxrwsr-x 2 root staff 4096 2010-07-31 16:21 site-library
bmccann@bmccann-htpc:~$ id -nG bmccann
bmccann adm dialout cdrom plugdev staff lpadmin admin sambashare
bmccann@bmccann-htpc:~$ touch /usr/local/lib/R/site-library/tmp
touch: cannot touch `/usr/local/lib/R/site-library/tmp': Permission denied
答案 0 :(得分:183)
您是否在进行组更改后退出并重新登录?请参阅:
Super User answer involving touch permissions failure
答案 1 :(得分:12)
为什么Linux用户不能编辑组中的文件?
我正在使用Ubuntu 12.04并遇到同样的问题,即用户无法写入允许其访问组的文件。例如:
whoami //I am user el
el
touch /foobar/test_file //make a new file
sudo chown root:www-data /foobar/test_file //User=root group=www-data
sudo chmod 474 /foobar/test_file //owner and others get only read,
//group gets rwx
sudo groupadd www-data //create group called www-data
groups //take a look at the groups and see
www-data //www-data exists.
groups el //see that el is part of www-data
el : www-data
立即重启终端以确保用户 和团体已经生效。以el。身份登录。
vi /foobar/test_file //try to edit the file.
产生警告:
Warning: W10: Warning: Changing a readonly file"
什么?我做的一切都正确,为什么它不起作用?
<强>答案:
完全重启计算机。停止终端不足以解决这些问题。
我认为发生的事情是apache2也使用www-data组,因此任务以某种方式阻止了用户和组的正确执行。您不仅需要注销,还必须停止并重新启动使用您的组的任何服务。如果重启没有得到它,你就会遇到更大的问题。
答案 2 :(得分:9)
我遇到了同样的问题,检查文件夹是否还有ACL规则!
如果在列出文件夹时可以看到+(加号),则表示它具有特殊的访问规则。例如:
[user_in_apache_group@web02 html]$ ls -l
total 16
drwxrwxr-x 16 apache apache 4096 Sep 4 13:46 ilias
drwxrwxr-x+ 15 apache apache 4096 Sep 4 13:46 ilias5
查看权限:
[user_in_apache_group@web02 html] getfacl ilias5
# file: ilias5
# owner: apache
# group: apache
user::rwx
user:user_in_apache_group:r-x
group::rwx
mask::rwx
other::r-x
这意味着我的用户(user_in_apache_group)没有该文件夹的写入权限。
解决方案是@techtonik所说的,为用户添加写权限:
[user_in_apache_group@web02 html]$ sudo setfacl -m u:user_in_apache_group:rwx ./ilias5
再次检查权限:
[user_in_apache_group@web02 html] getfacl ilias5
...
user:user_in_apache_group:rwx
...
希望它有所帮助。 ;)
答案 3 :(得分:7)
使用Linux ACL(访问控制列表) - 它是权限系统的更细粒度版本,
setfacl -R -m 'group:staff:rwx' -m 'd:group:staff:rwx' /usr/local/lib/R/
这为在其中创建的任何内容设置了目录和默认权限的活动权限。
如果您刚刚将自己添加到staff
群组,则无法重新登录,但您只能为当前会话设置权限。
答案 4 :(得分:5)
当用户无法访问/foo/bar/baz
目录时,我遇到了问题,即使他有权限,因为他无法访问bar
目录。
答案 5 :(得分:0)
在将内容添加到该文件之前,请检查您的父目录是否具有权限
sudo chmod -R 777 /yourDir/file.log