Display manager version (easier)
It is typically the job of display manager to show a login screen and start a user session. If you had one, it would be a path of least resistance to set it up to autologin. It is a widely used and probably well tested and supported solution. You would need to set it up to 1) autologin and 2) use your preffered session, but both are typically supported with the usual display managers supported by your linux (lightdm, xdm, whatever..).
On ubuntu 16.04 (non-server) I have the following in
You would need to install and possibly enable lightdm
apt-get install lightdm
Lightdm is the default ubuntu display manager. It is not installed by default on ubuntu server edition and you will be installing serveral packages so the harder manual way would be required if you wish to avoid them.
Ways of setting up a graphical login on ubuntu server is better described here https://askubuntu.com/questions/53822/how-do-you-run-ubuntu-server-with-a-gui#788193, after which you can set up autologin if you wish.
You may want to select your preffed type of session (openbox), by setting
/home/username/.dmrc to something like
I don't know what is exactly required to start an x session startx on boot, but I would suggest decomposing the problem to step-by-step process:
you say you startx works as root. It would be nice to verify you can log in as root on a console and start an x session with:
root@xyz # startx
Make sure you can start an X session when logged in as your preffered user.
myuser@xyz $ startx
Make sure you can start an X session as the preffered user, but while logged in as root, by building upon the previous command:
a) Use something like:
root@xyz # su -l myuser -c startx
quote the command if you need multiple arguments:
root@xyz # su -l myuser -c "startx arg1 arg2 .."
b) You may be able to skip this step if you set the user in the systemd unit.
Make it autostart.
a) Add the (3a) command to
/etc/rc.local and reboot.
b) Use a systemd unit like you described, with the command set according to 2/3. To test, you may use something like
root@xyz # systemctl stop autologin # make sure to reset service
root@xyz # systemctl daemon-reload # don't know if needed
root@xyz # systemctl start autologin
Once it works, you may need to enable it to autostart or whatever it is that systemd needs (not an expert).
root@xyz # systemctl enable autologin