I am trying to start a node.js application with on a low permissions user. All the files I know of are owned by the correct user and have permissions set reasonably well. I'm trying to use a script file to do this. I invoke the script with this command

sudo su - nodejs ./start-apps.sh

The shell script runs this command to start the app

cd "/home/nodejs/my-app"
npm start

npm start is documented here. It basically pulls the command to use out of the package.json file, which in our app looks like this:

// snip
"scripts": {
    "start": "node-dev app"

And it spits out the error:

> my-app@0.1.0-build.100 start /home/nodejs/my-app
> node-dev app

sh: 1: node-dev: Permission denied

npm ERR! spicoli-authorization@0.1.0-build.100 start: `node-dev app`
npm ERR! Exit status 126

That sh seems to be saying that it's reporting errors from the shell command. I don't think the problem is accessing the npm command itself, because if it were, the permission denied would be raised before any output from the npm command. But just to rule it out, here are the permissions for the npm command itself:

$ sudo find / ! \( -type d \) -name npm -exec ls -lah {} \;
-rwxr-xr-x 1 root root 274 Nov 12 20:22 /usr/local/src/node-v0.10.22/deps/npm/bin/npm
-rwxr-xr-x 1 root root 274 Nov 12 20:22 /usr/local/lib/node_modules/npm/bin/npm
lrwxrwxrwx 1 root root 38 Jan 14 07:49 /usr/local/bin/npm -> ../lib/node_modules/npm/bin/npm-cli.js

It looks like everyone should be able to execute it.

The permissions for node-dev look like this:

$ sudo find / ! \( -type d \) -name node-dev -exec ls -lah {} \;
-rwxr-xr-x 1 nodejs nodejs 193 Mar  3  2013 /home/nodejs/.npm/node-dev/2.1.4/package/bin/node-dev
-rw-r--r-- 1 nodejs nodejs 193 Mar  3  2013 /home/nodejs/spicoli-authorization/node_modules/node-dev/bin/node-dev
lrwxrwxrwx 1 root root 24 Jan 14 07:50 /home/nodejs/spicoli-authorization/node_modules/.bin/node-dev -> ../node-dev/bin/node-dev

I've already tried chowning the link to nodejs:nodejs, but the scrip experiences the same error.

Is there some file permissions problem I'm not seeing with the binary files? Or is this an npm/node-dev specific error?


The second node-dev is not executable, and the symlink points to that. Although the symlink is executable (symlinks are always 777), it is the mode of the file it points to that counts; note that calling chmod on the link actually changes the mode of the file it points to (symlink permissions never change).

So perhaps you need to add the executable bit for everyone:

chmod 755 /home/nodejs/spicoli-authorization/node_modules/.bin/node-dev
  • Oh yeah, I knew not to much with chmod'ing a symlink, I just tried the ownership change. I'll try the execution thing now - I can't believe I missed that. I guess I was thinking that the copy in my .npm directory would be executed for sure. I couldn't think how to check that, because node-dev isn't npm installed globally, so bash doesn't recognized the node-dev command; npm just magically figures out where & what to call. – Patrick M Jan 15 '14 at 18:27

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.