0

I'm trying to make the node_modules directory writable by www-group, but chmod isn't working. vagrant (user) is part of the www-data group as seen with the groups command.

Why can't I permit www-data (group) write permissions to this directory?

vagrant@vagrant-ubuntu-trusty-32:/var/www/src/my_app$ groups
vagrant www-data


vagrant@vagrant-ubuntu-trusty-32:/var/www/src/my_app$ ls -l
total 16
drwxr-xr-x 1 www-data www-data  136 Nov 27 22:56 apis
drwxr-xr-x 1 www-data www-data  170 Oct  6 23:24 assets
drwxr-xr-x 1 www-data www-data  170 Jan 15 19:38 controllers
drwxr-xr-x 1 www-data www-data  170 Jan 16 23:00 core
-rw-rw-r-- 1 www-data www-data 1300 Jan 16 23:09 favicon.ico
-rw-rw-r-- 1 www-data www-data 2602 Jan 17 20:03 Gruntfile.js
-rw-rw-r-- 1 www-data www-data 1352 Jan 16 16:27 index.php
drwxr-xr-x 1 www-data www-data  170 Jan 15 19:36 models
drwxr-xr-x 1 www-data www-data  578 Jan 17 03:00 node_modules
-rw-rw-r-- 1 www-data www-data  472 Jan 16 21:11 package.json
drwxr-xr-x 1 www-data www-data  204 Jan 17 01:35 views


vagrant@vagrant-ubuntu-trusty-32:/var/www/src/my_app$ sudo chmod g+w node_modules --verbose
mode of ‘node_modules’ changed from 0755 (rwxr-xr-x) to 0775 (rwxrwxr-x)


vagrant@vagrant-ubuntu-trusty-32:/var/www/src/my_app$ ls -l
total 16
drwxr-xr-x 1 www-data www-data  136 Nov 27 22:56 apis
drwxr-xr-x 1 www-data www-data  170 Oct  6 23:24 assets
drwxr-xr-x 1 www-data www-data  170 Jan 15 19:38 controllers
drwxr-xr-x 1 www-data www-data  170 Jan 16 23:00 core
-rw-rw-r-- 1 www-data www-data 1300 Jan 16 23:09 favicon.ico
-rw-rw-r-- 1 www-data www-data 2602 Jan 17 20:03 Gruntfile.js
-rw-rw-r-- 1 www-data www-data 1352 Jan 16 16:27 index.php
drwxr-xr-x 1 www-data www-data  170 Jan 15 19:36 models
drwxr-xr-x 1 www-data www-data  578 Jan 17 03:00 node_modules
-rw-rw-r-- 1 www-data www-data  472 Jan 16 21:11 package.json
drwxr-xr-x 1 www-data www-data  204 Jan 17 01:35 views



vagrant@vagrant-ubuntu-trusty-32:/var/www/src/my_app$ cd node_modules && mkdir test
mkdir: cannot create directory ‘test’: Permission denied

I also tried using the -R (recursive) flag on the CHMOD command which didn't help, I still can't write to directories; however, I can write to files as the group has write access. Why isn't this working for directories?

vagrant@vagrant-ubuntu-trusty-32:/var/www/src/my_app/node_modules/grunt$ ls -l
total 20
-rw-rw-r-- 1 www-data www-data 1242 May  9  2014 appveyor.yml
-rw-rw-r-- 1 www-data www-data  127 May  6  2014 CONTRIBUTING.md
drwxr-xr-x 1 www-data www-data  136 Oct  2 12:41 internal-tasks
drwxr-xr-x 1 www-data www-data  170 Oct  2 12:41 lib
-rw-rw-r-- 1 www-data www-data 1062 May  6  2014 LICENSE-MIT
drwxr-xr-x 1 www-data www-data 1020 Nov 20 20:29 node_modules
-rw-rw-r-- 1 www-data www-data 2319 Nov 20 20:32 package.json
-rw-rw-r-- 1 www-data www-data  900 May  6  2014 README.md
Jack
  • 11
  • 1
  • 2

3 Answers3

1

They might be your groups now but not for the shell you are using.

You can see what supplementary groups you are in in this case by running

grep Groups /proc/self/status

Try relogging in again to see if this fixes the problem.

Matthew Ife
  • 23,357
  • 3
  • 55
  • 72
1

Only the actual owner of a file or directory can change its permissions. Just being a member of the file's group and having group write access is not enough.

But if you have write access to the directory the file is in, and read access to the file itself, you can always make a copy of the file (causing the copy to be owned by you), delete the original and then rename the copy to have the same name the original used to have.

telcoM
  • 4,448
  • 15
  • 25
0

If you want that and everything under it add the -R flag

sudo chmod g+w -R node_modules --verbose

That is recursive and will do everything g+w

Mike
  • 22,310
  • 7
  • 56
  • 79
  • I couldn't write to the node_modules directory, so recursive wouldn't help. I just need the node_modules directory itself to be writable by the www-data group. – Jack Jan 17 '15 at 20:26
  • Are there any other commands or flags i could use to troubleshoot this? – Jack Jan 17 '15 at 20:40