Ok another thread in the forum, brought this to mind, (Wizard10000) mentioned that the only display manager which doesn't launch-run X as root is GDM. This is likely to be irrelevant in future, with Wayland and honestly I don't overly care as it is anyway but still on with the thread.

1. Using systemd to autologin a user.
Create a directory named getty@tty1.service.d and a file in it called override.conf in the following location.
- Code: Select all
/etc/systemd/system/getty@tty1.service.d/override.conf
Here's what you'd add to that override.conf file.
[Service]
Type=simple
ExecStart=
ExecStart=-/sbin/agetty --autologin yourusername --noclear %I 38400 linux
That's what it'll do, automatically login the user named, where it says yourusername. Put the desired username there.
2. To automatically startx edit the .profile file in your users /home directory and add this to the bottom.
- Code: Select all
#Startx Automatically
if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/tty1 ]]; then
. startx
logout
fi
Ok, that will automatically run startx, when your user logs in.
3. Now say you have several DE's/WM's installed. You'll obviously want to be able to pick and switch between them. This is where update-alternatives comes into it.
Enter the following command to pick which will be the default xsession, until it's changed.
- Code: Select all
sudo update-alternatives --config x-session-manager
Select the one you want to be default and you're good to go. ALMOST. Most DE's etc will be well behaved and will add a selection for themselves to x-session-manager for you. However sometimes I've found that won't be the case however you can add an entry for it yourself. ie: Let's take fluxbox by way of example. I want to add it to the x-session-manager section of update-alternatives, so I can choose it there whenever I want. Here's how ...
- Code: Select all
sudo update-alternatives --install /usr/bin/x-session-manager x-session-manager /usr/bin/startfluxbox 40
In the above, I'm installing something to the x-session-manager group of update-alternatives, in this case, fluxbox, /usr/bin/fluxbox is where fluxbox errrr, lives

NOTE: Ok another scenario, the above is perfectly fine for a single user system but what about a multi-user one or one on which you want to be able to login more than one username. Easy, peasy, just skip step 1 (or remove the directory/override.conf file. You'll be met with a command-line login to enter the user and password you want to use.
Finally, you likely already have a display manager running. For all this automagic-ness to work, you'll have to change that. Couple options, remove the display manager from your OS, you can always reinstall it later if desired. Another would be to use "sudo systemctl disable lightdm" to disable lightdm and keep it from automatically starting every time the system boots up. If at some point in future you wish, re-enable the sucker with "sudo systemctl enable lightdm" and you may also need to run "sudo dpkg-reconfigure lightdm" too. After which the sucker should be up and running again.
IMPORTANT NOTE: Make sure you have the xinit package installed "dpkg -l |grep xinit" if not yep, install it ! "sudo apt install xinit", just found out the hard way I didn't have the stupid thing on a 32b/Stretch minimal netinstall OS when went to remove lightdm and set this junk up. Kept getting problems until did the above and installed the dang xinit = startx command.