Raspberry Pi has been the most successful device in recent years, everyone right from students, professionals as well as enthusiast have fascinated the device for it’s size, power consumption and capabilities. It can be used for extremely light weight task to self-hosting large applications for home.
One of the use cases is attaching a screen to the device and creating a slideshow of pictures for display at home. In such cases, the devices need to be able to auto-login itself with the proper user and able to start the required application with proper right so it can resume the slideshow. This is just one of the use cases, which I personally encountered. Auto-login might be a requirement in multiple so we decided to write-up about it.
Step 1 – changing the configuration
Raspberry Pi OS uses LightDM to mange the displays as it is lightweight and easy to use. It uses a configuration file which we are going to modify using the following command.
sudo nano /etc/lightdm/lightdm.conf
After you open up the lightdm.conf file you need to scroll down and find the following these two lines to modify them:
#autologin-user=
#autologin-user-timeout=0
You need to un-comment these to lines so that they looking like following and replace the <username> with the username you want to application to be able to login in. In most cases, it’s going to root, but it can be another user as well if you want the user to have some constrains.
autologin-user=<username>
autologin-user-timeout=0
When you have finished editing this file press “Ctrl+x”, then press “y” to save, and then “Enter” to exit the file.
Step 2 – Enable auto-login
To enable auto-login using the LightDM library, we need to enable it in the auto-login module of the manager. To do it, we modify the lightdm-autologin file, using the following process.
sudo nano /etc/pam.d/lightdm-autologin
The line that we need to edit is:
auth required pam_succeed_if.so user != root quiet_success
We need to hash out or comment out that line by editing it to look like this:
#auth required pam_succeed_if.so user != root quiet_success
After you have made this change go ahead and save the file by pressing “Ctrl+x“, then press “y“, then “Enter” to exit.
Once you have done modifying the above files, just reboot and checkout if the device gets auto-logged in with the specified user. The only thing remaining after that is configuring the application to auto start at boot, but we will cover that in another article.