Auto login and startx(desktop) without a display manager.

Share your own howto's etc. Not for support questions!

Auto login and startx(desktop) without a display manager.

Postby Deb-fan » 2019-10-17 15:29

Yet another auto-login and start your prefered desktop/windows manager without a display manager running on the OS thread.

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

Here's what you'd add to that override.conf file.
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

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/fluxbox 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 :D and I'm giving it a priority of 40 there. Although it doesn't overly matter. Once it's selected it'll launch as default x-session until something else is chosen.

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.
Last edited by Deb-fan on 2020-02-22 13:08, edited 3 times in total.
Posts: 517
Joined: 2012-08-14 12:27

Re: Auto login and startx(desktop) without a display manager

Postby Deb-fan » 2019-10-17 15:46

Lol :) Yeah I know you have one up too Hoas. Was just thinking about this at the moment. No shortage of ways for sure but still are definitely differences between them. No worries, hope you and yours are well fellow nixer. :)

Btw: Thanks for posting this here too. May snag what you've got for the edit to .profile file. Though yeah, the above works fine. Yours is less text/typing though.
Posts: 517
Joined: 2012-08-14 12:27

Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 1 guest