Debian – How to start headless X upon boot for non-root users in Debian

debianxserverxvfb

My requirement is a little different from this one in that I would like to launch a window manager for each of two non-root users upon boot.

For testing, first I prepare the following lines in .xinitrc and/or .xsession in home directories of user2 and user3 like so:

#!/bin/sh
exec icewm

Then I manually login to virtual console as user2 or user3 or open an xterm window and type this command:

xinit -- /usr/bin/Xvfb :3 -cc 4 -screen 0 1024x768x16

This does the job – icewm and Xvfb run behind the scene.

Now I want to automate the login and command xinit on boot. However none of the following approaches work:

Either manually type these two commands as root or place them in /etc/rc.local:

su -l user2 -c xinit -- /usr/bin/Xvfb :3 -cc 4 -screen 0 1024x768x16

No protocol specified
IceWM: Can't open display: :0. X must be running and $DISPLAY set.

start-stop-daemon --start -u user2 -g user2 -b --pidfile /tmp/pid --exec /usr/bin/xinit -- -- Xvfb :3
ps ax

[Xorg] <defunct>

Helps will be greatly appreciated!

[Edit after testing alex.d.'s approach]

File /home/user2/.xsession:

#!/bin/bash
export DISPLAY=localhost:3
export XAUTHORITY=$HOME/.Xauthority
exec icewm

Issue this command as root:

su -l user2 -c /usr/bin/startx -- /usr/bin/Xvfb :3 &

I get this:

hostname: Name or service not known
xauth: (stdin):1:  bad display name "example.com:2" in "add" command

IceWM: Can't open display: localhost:3. X must be running and $DISPLAY set.
xinit: giving up
xinit: unable to connect to X server: Connection refused
xinit: server error
xauth: (argv):1:  bad display name "example.com:2" in "remove" command

Any idea? Please!

Best Answer

This is my working approach.

file /etc/systemd/system/john.service:

[Unit]
Description=xinit - user "john"

[Service]
User=john
Group=john
ExecStart=/usr/bin/xinit openbox-session -- /usr/bin/Xvfb :1 -nolisten tcp
ExecStopPost=/usr/bin/killall -u john

[Install]
WantedBy=multi-user.target

file /home/john/.config/openbox/autostart:

wine my_program.exe

Thank you all for the helps!