I chowned recusively /srv/site to www-data:www-data and chmodded it recursively with ug+rwx. I then added myself to group www-data.

$ sudo usermod -a -G www-data cyrus
$ sudo chgrp -R www-data /srv/site
$ sudo chmod -R ug+rwX /srv/site

However, why do I still get permission denied?

$ ls /srv/site
ls: cannot open directory /srv/site: Permission denied

$ cd /srv; ls -la   
total 12
drwxr-xr-x  3 root     root     4096 Aug 13 02:42 .
drwxr-xr-x 24 root     root     4096 Aug 11 21:20 ..
drwxrwx--x 10 www-data www-data 4096 Aug 13 02:42 site

Have you logged in again. Group membership is not normally reset once a user has logged in.

  • 1
    Run the id or groups commands to see your current groups. You will probably find that your group list has not been updated. It doesn't take effect on existing processes/sessions/etc. – Etan Reisner Aug 12 '13 at 19:24
  • Yes, when I ran groups, www-data was not there. Thank you so much! – Zhianc Aug 12 '13 at 20:26

As pointed out you have to re-login to refresh a group vector.

To not loose the context of your work (eg. other opened terminals), you might consider

user$ su - user


user$ newgrp www-data

then from there on you can spawn new programs with complete group vector.

In case of newgrp, what you are ending up is your primary group to be www-data (in this case), which is significant eg. when creating new files.

In case of su, I wonder how to achieve the same effect with sudo (sudo -iu user doesn't refresh the group vector).

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.