Cannot make directory '/var/run/screen': Permission denied

Sometime, usually after a crash or sudden shutdown, screen refuses to start. Commands like

screen
screen -ls
screen -r
screen -d

result in the following output

Cannot make directory '/var/run/screen': Permission denied

What's the issue here? How can I fix this?


Solution 1:

Found a solution that doesn't require regular sudo on restarts

From 'Eric Z Ma' @ systutorials:

The directory /var/run/screen/ is the socket directory for screen.

Fortunately, screen reads a environment variable SCREENDIR to get an alternative socket directory.

So to work around it, you can create a directory, such as ~/.screen:

mkdir ~/.screen && chmod 700 ~/.screen

and export the SCREENDIR to point to that directory:

export SCREENDIR=$HOME/.screen

You can also put this line into you ~/.bashrc so that it will also take effect afterwards.

Solution 2:

This issue has been documented here. In short,

/etc/rcS.d/S70screen-cleanup is running via upstart much earlier than it expects to have run, and is failing to correctly clean up that directory.

It can be fixed with the following command

sudo /etc/init.d/screen-cleanup start

Solution 3:

I ran into this while running a Centos / RHEL 7 based distro, and it doesn't have anything named 'screen-cleanup' anywhere under /etc.

A workaround I found was to simply run sudo screen and then immediately exit from it.

After that I was able to run screen without any special privileges, so it appears to clean up /var/run approriately up when given the chance.

Solution 4:

I can fix this problem by executing the following commands.

sudo mkdir /var/run/screen
sudo chmod 777 /var/run/screen

Solution 5:

In my case the screen-cleanup service was masked, on Debian "buster" 10.4:

$ systemctl is-enabled screen-cleanup.service

masked

And

$ file /lib/systemd/system/screen-cleanup.service

/lib/systemd/system/screen-cleanup.service: symbolic link to /dev/null

Which causes the following:

$ systemctl enable screen-cleanup.service

Synchronizing state of screen-cleanup.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable screen-cleanup
Failed to enable unit: Unit file /lib/systemd/system/screen-cleanup.service is masked.

The following did the trick to create the run-directory on every boot. Remove the symlink to /dev/null manually (systemctl unmask didn't work):

rm /lib/systemd/system/screen-cleanup.service

Then enable the service:

systemctl enable screen-cleanup.service

And start it:

systemctl start screen-cleanup.service