This small C program, when properly installed, simplifies use of screen(1) on the Windows Subsystem for Linux (WSL) by avoiding the need to run as root or via sudo(8). The directions in this guide, and in the comments atop the program itself, arrange for this utility to be installed setuid root. When run, this utility creates and sets required permissions on the folder used by screen(1) to store its communication sockets.
This utility is only likely to be of use under WSL; under other environments, the problem addressed by this utility does not seem to occur.
For an alternative solution to this problem on WSL, along with an explanation of the problem's origin, see "Running Windows Subsystem For Linux Services At Startup" by Adrian Stoll. In short (and that page is at this writing very short), systemd does not run on WSL and thus the normal initialization for Screen doesn't either. This author has not tested Adrian's solution and wrote this utility before noticing it.
This utility is covered by a BSD-style license; see the top of the source code file for details.
This utility is intended for installation and use in Linux distributions run under the Windows Subsystem for Linux (WSL). It may run in other settings, with or without modification, but is by this author assumed to be unnecessary there.
To install this utility, perform these steps:
scrfix.htm. If you do not have the required
unziputility in your Linux distro, use
apt install zipor
apt install unzip, or your distro's equivalents. (This author chose the Zip format rather than the Tar format for its wider familiarity to native Windows users.)
/usr/bin. Be sure that the folder you choose is checked for commands when you type commands; i.e., that it is referenced in your
PATHenvironment variable. A good way to check this in most shells is to type this command and look for your chosen folder in the result:
This should simply compile the utility without further output. If this fails, you may first need to
cc -o scrfix scrfix.c
apt install gcc(or similar depending on your Linux distribution). If you receive errors other than an error like "command not found," please report the error to this author.
These commands arrange for scrfix to run as root regardless of your user priveleges and without prompting for a password.
chown root:root scrfix
chmod 4755 scrfix
After installation, run scrfix once every time wsl starts an instance. Then screen(1) will work without a sudo.
It may be most convenient to arrange for this utility to be run once per launch of your WSL distribution. This
can generally be done by calling it from within a shell script that launches exactly once per WSL login.
For Bash users, this is the
For users of tcsh, this is the
If you already launch Screen automatically, just call this utility first.
This utility simply creates and sets required permissions on a folder called
Screen uses to manage its communication sockets.
In most environments, this folder can be created one time and reused by all users on the system. In WSL,
however, the folder resides in an area that is recreated every time a WSL instance is spawned. As a result,
the folder and its permissions must be re-asserted often.
It is of course necessary for this utility to run as root to make and set permissions on this folder. The
program is written in C, as opposed to Python or another scripting language, to facilitate use of the
setuid bit; that is, a permission bit set on the utility itself that allows it to execute with the
priveleges of its file owner. The file must be owned by root for this to work as intended.
The net result of all this is that the required setup can be established without requiring
or a root shell.
Here is the revision history of this utility, most recent revision first: