cannot access /dev/null: Permission denied, although crw-rw-rw- 1 root root 1, 3 Sep 21 12:05 /dev/null
On user postgres:
$ ls -l /dev/null
ls: cannot access /dev/null: Permission deniedThought on user root, permissions are correct:
# ls -l /dev/null
crw-rw-rw- 1 root root 1, 3 Sep 21 12:05 /dev/nullI have tried to re-create it:
# rm /dev/null && mknod -m 0666 /dev/null c 1 3But the result is the same. I am on a VPS with a debian 7 and kernel 2.6.32 on a x86_64
04 Answers
The problem came from the permissions to /dev:
# ls -ld /dev
drwx------ 3 root root 4096 Sep 21 12:12 /devSo /dev was not accessible by users.
# chmod a+x /dev
# chmod a+r /devSolved the problem.
4I had a similar problem, and came here by searching for the symptoms, but the solution didn't fit my case. So I'd like to add another possible reason even if it's not exactly fitting the OP.
In my special case I used proot (a nice chroot wrapper). But the permissions were correct on /dev/null and /dev itself.
It happened to be the mount of the chroot directory, which I did via thunar as a normal user. So, in this case the mount did not have the correct permissions.
You have a bad time to find this, because you don't see these permissions, when only looking at the files.
The general solution path would be to start checking conditions at the problem location (/dev/null) and step out to the next level(s) (/dev), then the mount, the file system etc., whatever comes next.
On each step you may have several preconditions, each having it's own outer levels. E.g. the user could be in a wrong group, which leads to the group configuration file, which could have wrong permissions etc.
Obviously, you have to follow a kind of tree in general.
I couldn't solve this one myself, so this is what I did:
mycommand.sh | echo -nThe echo command does not pay attention to standard input, so it will be discarded. And the -n is so that a useless newline is not printed to stdout.
chmod a+rw /dev/null /dev/random /dev/urandom /dev/ptmx /dev/tty /dev/zero /dev/full /dev/fuse /dev/net/tunthis is what solve my problem on VPS. Please notice, that after you reboot your server - you have run this command again