I'm trying to setup folder access to a group so that all members of that group can create/edit/delete files within the folder.

# create my group and add a member
sudo addgroup dev
sudo adduser martyn dev

Now, logged in as "martyn", check my user has been added to "dev" group

groups martyn
martyn : martyn dev

Now I want to change the group ownership of my project folder so all members of that group can edit it and files/folders within it.

sudo chgrp -R dev myproject

Just to check:

martyn@localhost:/var/www$ ls -l
total 4
drwxrwxr-x 3 dev dev 4096 May 31 15:53 myproject

Now here's where it fails. I want to create a file within myproject (logged in as "martyn", a member of "dev"):

vi myproject/test

..but when I try to save the file I get the following error:

"myproject/test" E212: Can't open file for writing

Why, as user "martyn" which is a member of "dev", can I not write this file? Even if I create the file so it exists, change the ownership to "dev" then try to edit and save - I get the same error.


You can try to change/set the ownership of the directory with the chown command, like this:

chown -R dev:dev myproject/

and then set the permissions with the chmod command:

chmod -R 0775 myproject/

The 0775 bit notation sets the directory mode to rwxrwxr-x, which gives the user dev and all members of the dev group rwx access to the directory and files.

Try this instead of the chgrp command. You may also try to reboot your machine, just in case. Good luck.

  • Could the downvoter at least note what is wrong with this answer? – arielnmz May 31 '14 at 9:16
  • I don't know what the down vote was for but anyway you solved my problem. Thanks :) – Martyn May 31 '14 at 12:12
  • You're welcome. I'm always glad to help. – arielnmz May 31 '14 at 16:02

This works for me on Arch Linux:

$ sudo useradd martyn
$ sudo passwd martyn
$ sudo groupadd example 
$ sudo usermod --append --groups example martyn
$ sudo mkdir /var/www /var/www/myproject
$ sudo chgrp example /var/www/myproject
$ sudo chmod g+w /var/www/myproject
$ su - martyn
$ groups
example martyn
$ touch /var/www/myproject/file
$ ls -l /var/www/myproject/file
-rw-r--r-- 1 martyn martyn 0 May 31 11:13 /var/www/myproject/file

Are you sure you don't have SELinux enabled (run getenforce)?

  • Thanks. No I don't have SELinux installed. – Martyn Jun 1 '14 at 1:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.