Permissions Error: -bash: /dev/null: Permission Denied – How to Fix

permissions

I'm trying to create a new user on a Centos 6 system.

First, I do

useradd kevin

Then, I tried to run commands as that user

su - kevin

However, I get the following error messages

-bash: /dev/null: Permission denied
-bash: /dev/null: Permission denied
-bash: /dev/null: Permission denied
-bash: /dev/null: Permission denied
-bash: /dev/null: Permission denied
-bash: /dev/null: Permission denied
[kevin@gazelle ~]$

And I can't do very much as that user.

The permissions on /dev/null are as follows:

-rwxr-xr-x  1 root root           9 Jul 25 17:07 null

Roughly the same as they are on my Mac,

crw-rw-rw-   1 root   wheel         3,   2 Jul 25 14:08 null

It's possible, but really unlikely, that I touched dev.

As the root user, I tried adding kevin to the root group:

usermod -a -G root kevin

However I still am getting /dev/null permission denied errors.

Why can't the new user write to /dev/null?
What groups should the new user be a part of?
Am I not impersonating the user correctly?
Is there a beginners guide to setting up users/permissions on Linux?

Best Answer

Someone evidently moved a regular file to /dev/null. Rebooting will recreate it, or do

rm -f /dev/null; mknod -m 666 /dev/null c 1 3

As @Flow has noted in a comment, you must be root to do this.

1 and 3 here are the device major and minor number on Linux-based OSes (the 3rd device handled by the mem driver, see /proc/devices, cat /sys/devices/virtual/mem/null/dev, readlink /sys/dev/char/1:3). It varies with the OS. For instance, it's 2, 2 on OpenBSD and AIX, it may also not be always the same on a given OS. Some OSes may supply a makedev / MAKEDEV command to help recreate them.

Related Question