Skip to content

1.1.3 Autologin

PortalMario edited this page Jan 18, 2023 · 1 revision

Autologin

After the boot procedure is done, ubuntu will show a login prompt on the first connected video output. (In this case, the only HDMI port on the motherboard aka tty1.) Of course, we don’t want to see any kind of OS-Related messages/prompts. The first thing, the user should see on the screen is a custom bootup animation. After the animation played, emulationstation (retropie emulator frontend) should be started on the same screen. Unfortunately, emulationstation cannot be started with root privileges this forces us to use a regular user account to start the application and therefore the user has to login. (If emulationstation would run fine with root privileges, we could avoid those autologin related steps and create a startup systemd service.)

User

As we don’t want to unnecessary complicate things, we just use the primary user that was created during the ubuntu installation.

Systemd: getty/agetty Service

To reduce the boot time of the system we configured systemd to boot directly into the CLI instead of the graphical ubuntu desktop. Ubuntu lets us configure an autologin per default during the initial installation of the OS however this method only applies to the graphical login. To setup an autologin for a specific user that applies to the CLI, we need to configure a specific service called: getty@tty1. This service starts automatically and calls the agetty command for tty1. Agetty opens a tty port and prompts an login dialog.

To customize predefined/existing systemd services we need to create an "override.conf" for the specific service. This is simply done by creating a .d directory for the desired service at /etc/systemd/system and creating a file called: override.conf.

In our case we want to customize the login behavior for the first tty (tty1) because this is the tty that the user will always land on when booting the system. (You could say that tty1 always points to the first connected screen like the first connected HDMI-Port.)

$ mkdir /etc/systemd/system/getty@tty1.service.d/
$ nano /etc/systemd/system/getty@tty1.service.d/override.conf

After we created the correct directory, we open a new "override.conf" file. We add the following contents to the file:

# Clearing existing exec (line 3).
[Service]
ExecStart=
ExecStart=-/sbin/agetty --skip-login --nonewline --noissue --autologin <USER> %I $TERM
Type=idle

As you can see, we mainly edit the [Service] section of the getty@tty1 service.

Note: We clear the ExecStart variable once (line 3). Otherwise systemd will tell us that the variable is already used/filled and cannot be "overridden".

As you can see, we tell agetty to skip the login prompt messages with --skip-login and perform an autologin for the following user name. Therefore, we just have to replace <USER> with the desired username. We need to make sure that the directory and the override file have the correct permissions and the correct ownership:

$ chown -R root:root /etc/systemd/system/getty@tty1.service.d/
$ chmod -R 644 /etc/systemd/system/getty@tty1.service.d/override.conf

To apply the systemd service changes run the following command:

$ systemctl daemon-reload

Conclution

When rebooting the system, we should now land directly on a shell prompt right after the boot process finishes without having to authenticate. (Remember: the boot process only shows a black screen. So, the first thing the system now displays is the bash shell prompt.)

Clone this wiki locally