How I use Linux desktop at work - Part4 - Display Manager With Autologin
Part 4 of the series How I use Linux desktop at work where I describe how I’m building a new Vagrant configuration to use for coding on Windows Host systems.
This post describes the learning process to setup LightDM with autologin.
As with previous posts, I will go over the research and manual implementation first, then go over how to automate it.
In part 3, I described how I automated the build of the VirtualBox guest additions using vagrant. Part 4 will improve our current box by swapping the display manager to LightDM and setup autologin.
Previous posts:
In the post, I’ll cover:
Rationale
Installing lightDM, a greeter
Configure autologin
Automating the whole thing
Thoughts and next steps
Steps 1-4 are describing the manual process while step 5 describe how I automated this in the Vagrantfile.
Note: You can find the sources created during this post in my github devbox-arch repository.
Rationale
I want to setup autologin since I want to get in the guest linux box ASAP without unecessary login.
I only want to do this on a vagrant box under certain conditions:
This vagrant box has a virtual NAT network enabled and no port forwarded except ssh using ssh keys setup by vagrant
This box is secured by my host OS credentials. I cannot get in this box without unlocking my Host desktop.
Installing lightDM, a greeter, and XSession
I really like the quality, somewhat simplicity and features that lightDM gives.
The setup I usually put in place with lightDM:
lightDM itself
the gtk greeter. There are better greeter, but this one is simple, available everywhere
a xsession that starts my ~/.xinitrc
In arch, this means installing lightdm, lightdm-gtk-greeter, and xinit-xsession (AUR)
For the first two, its simple:
pacman -S lightdm lightdm-gtk-greeter
xinit-xsession is part of AUR, so it’s a bit more involved as you have to build it from source.
# some required tools
pacman -S git fakeroot
# now clone the AUR git repository
git clone https://aur.archlinux.org/xinit-xsession.git
cd xinit-xsession
makepkg -sic --noconfirm
Now time to enable lightdm:
systemctl enable lightdm
systemctl start lightdm
You’ll now see the lightdm greeter with the vagrant user pre-selected.
If you want to login, the password is vagrant.
Note that you can select xinitrc as a session in the session selection at the top right of the screen.
Configure autologin
Autoconfig is configured in lightDM main configuration /etc/lightdm/lightdm.conf.
You must set the following two properties to get autologin with xinit session enabled:
[seat:*]
autologin-user=vagrant
autologin-session=xinitrc
Note: you have to uncomment the two properties under the existing seat configuration.
You can restart lightdm to see it in action:
systemctl restart lightdm
You also need to add the autologin group and add user vagrant to this group:
groupadd -r autologin
usermod -a -G autologin vagrant
Automating the whole thing
All changes were made to the 2-core.sh script.
The interesting part is how to install xinit-xsession and then setup lightdm for autologin.
Installing xinit-xsession using AUR comes to one command:
cd /tmp
&& sudo -u vagrant git clone https://aur.archlinux.org/xinit-xsession.git && \
cd xinit-xsession && \
sudo -u vagrant git checkout 7cae213844b && \
sudo -u vagrant makepkg -sic --noconfirm
Note: makepkg needs to run as a regular user, so you need to clone, and call makepkg using vagrant.
Enabling autologin can be done using sed:
sed -i -e 's/# *autologin-user=.*/autologin-user=vagrant/' /etc/lightdm/lightdm.conf
sed -i -e 's/# *autologin-session=.*/autologin-session=xinitrc/' /etc/lightdm/lightdm.conf
The sed’s -i option enables in-place editing which change the file specified.
The last part, creating a .xinitrc that calls openbox:
cat <<EOT > ~vagrant/.xinitrc
#!/bin/bash
exec /usr/bin/openbox
EOT
chown vagrant:vagrant ~vagrant/.xinitrc
chmod +x ~vagrant/.xinitrc
Here, the file is created as root, and then ownership is transferred to the vagrant user.
Thoughts and next steps
I hope I am able to demonstrate how easy it is to provision a Linux development VM using vagrant and some unix scripts.
The hardest part is done, getting a foundation to install development tools and configuration.
In next post, I’ll configure this VM using chezmoi. This will allow me to bring my dotfiles and installation scripts.
When I started this blog, I was hoping it would be useful to others. Now I see that it may be as useful to me. It makes me thinks of my goals, think about improving, it makes me learn.
I hope this series inspires people to shape tools to meet their needs.
This is day 6 of my #100DaysToOffload. You can read more about the challenge here: https://100daystooffload.com.