I have a file

-rw-rw-r-- 1 root mygroup 0 Sep 10 14:54 /etc/nginx/mygroup.txt

The access rights are set so that the group mygroup has read and write permissions for the file. Writing the file with a member of mygroup works when editing with vi /etc/nginx/mygroup.txt. However, when I try to append a text to the file with the same user using

echo "blaa" >> /etc/nginx/mygroup.txt

I get

-sh: 3: cannot create /etc/nginx/mygroup.txt: Permission denied

The directory permission for the containing directory are

drwxr-xr-x  6 root root    4096 Sep 10 16:07 nginx

The user is able to list the contents of the directory.

Why does this happen and how can I add a line to the text file from bash without using a text editor?

Additional information based on comments:

The user has no sudo rights.

Is this a duplicate of Why can't sudo redirect stdout to /etc/file, but sudo 'nano' or 'cp' can? ? I don't think so, because running

printf "blaa" | tee /etc/nginx/

produces also

tee: /etc/nginx/whitelist-jutik.txt: Permission denied

Also all the other suggested duplicate questions are for users with sudo rights, so I think this question is not a duplicate of any of them.

Edit: finding this question solved the problem: Group member cannot write even with write permission

Apparently the group permissions were not completely in effect. Logging in again with the user solved the problem, he can write the file with both vi and echo.

  • What are the directory permissions? – glenn jackman Sep 10 '18 at 14:18
  • 1
    You should also edit the question to demonstrate that this is not unix.stackexchange.com/questions/19707 , unix.stackexchange.com/questions/42801 , unix.stackexchange.com/questions/1416 , or unix.stackexchange.com/questions/31322 yet again. (-: – JdeBP Sep 10 '18 at 14:23
  • 1
    When you were using vi, did the file already exist? Similarly: when you were using echo did the file already exist? Your user doesn't have permission to create a file in that directory but it does have permission to modify the existing file as shown to us. – roaima Sep 10 '18 at 14:30
  • 1
    In both cases? Or just for vi? Or just for echo? – roaima Sep 10 '18 at 14:33
  • 1
    Simon, please write an answer summarising your findings rather than updating the question. You can then accept it (tick-mark alongside the voting buttons on the left) so we can (easily) see the question's been answered. – roaima Sep 10 '18 at 15:42