How To Configure Autologin on the Raspbian Buster Console

I have a Raspberry Pi 4 running Raspbian 10 (Buster) inside a tester. When the OS boots I would like it to autologin a user and run a program the operator interacts with. The raspi-config tool has an option for booting to a console prompt with autologin but it does not seem to work. When the Pi reboots, a user name and password is always requested.

“Buster” uses systemd. In my searching so far the articles I’ve come across for autologin all reference older SystemV init changes for autologin.

Any advice on how to manually configure autologin at a console prompt or how to troubleshoot why the configuration tool isn’t doing what I think it should are appreciated.

Tim

A word of warning when you enable this, anyone can access your system as there is no username and password authentication enforced. So do this only if you need it, and 100% sure nobody else would access your computer or RPi. Otherwise, use ssh for login.

You can automatically log in on Debian 9/10/11 using the command line at boot time. All command must run as root user. The procedure is as follows:

Step 1 - Find full path to agetty

Run the type command or command command:

type -a agetty
agetty is /usr/sbin/agetty
agetty is /sbin/agetty

Note down the full path /usr/sbin/agetty

Step 2 - Edit the /etc/systemd/logind.conf file on Raspbina buster

Type the following command to configure the systemd login manager:

vim /etc/systemd/logind.conf

Find the following which defines how many virtual terminals (VTs) to allocate by default that

#NAutoVTs=6

Replace or update as follows (I am setting to 1)

NAutoVTs=1

Save and close the file.

Step 3 - Configuring auto log in on Debian 9/10/11 Linux when using systemd

Create a new systemd override as follows for tty1:

systemctl edit getty@tty1.service 

Append the following (use full path /usr/sbin/agetty as per your system displayed by the type command):

[Service]
ExecStart=
ExecStart=-/usr/sbin/agetty --autologin nixcraft --noclear %I $TERM

Save and close the file.

Step 4 - Enable the service at boot time if not enabled

Execute:

systemctl is-enabled getty@tty1.service
systemctl enable getty@tty1.service

Reload changes:

systemctl daemon-reload

Step 5 - Test it

Reboot the system

reboot

FYI, you can start/stop/restart service as follows:

systemctl start getty@tty1.service
systemctl stop getty@tty1.service
systemctl restart getty@tty1.service
systemctl status getty@tty1.service

OPTIONAL

Want to disable GUI login and only do text login? Run:

systemctl set-default multi-user.target

Go back to GUI login? Run

systemctl set-default graphical.target

What is use case @tpmcd? In what situation a Linux server could potentially be used without login? I am just curious and not aware such a thing was even possible on Linux, so I ask.

In this application, the Raspberry Pi is one component in a piece of test equipment that performs various tests on a computer board which ultimately runs embedded Linux in a product. The Pi has two main functions: 1) It provides tftp and nfs servers so the DUT (Device Under Test) can load and run Linux without having to program it and also run a test application that is written for the specific hardware being tested. 2) The second function is an external monitor on the tester and some dedicated key switches on the tester, serve as the user interface to the person operating the tester.

The servers would not need any user to be logged in to do their jobs. The operator interaction with the tester requires an application on the Pi to be run so that aspect needs an operator logged in.

Tim

1 Like

@nixcraft – Thank you for the detailed instructions.

When I do the configuration as you advised, the user logs into the computer, however the login prompt still appears and I cannot do anything until I enter the user name and password. After that I get a command prompt however I am unable to issue any of the regular Linux commands, etc. once I get the prompt. There is a message…

bash: cannot set terminal process group (614): Inappropriate ioctl for device
bash: no job control in this shell

Your example used tty1 which I did try. I got the behavior I mention above.

Before doing any of the above I looked and according to the tty command, by terminal is ttyS0 not tty1. I tried your instructions using ttyS0 where you mentioned tty1 and I still get the login prompt but I cannot login at the prompt, I just have to turn power off to the Pi.

Advice?

Tim

Edit the:

systemctl edit serial-getty@ttyS0

Append the following for root to auto login:

[Service]
ExecStart=
ExecStart=/sbin/agetty -o '-p -- \u' --keep-baud 115200,38400,9600 --noclear --autologin root ttyS0 vt220

Then

systemctl daemon-reload
systemctl restart serial-getty@ttyS0

If you still prompted for a password, then edit the /etc/pam.d/login

nano /etc/pam.d/login

Append:

auth sufficient pam_listfile.so item=tty sense=allow file=/etc/rootttyloginfile onerr=fail apply=root

Create a new /etc/rootttyloginfile and add the device:

/dev/ttyS0

Then

systemctl restart serial-getty@ttyS0

Reboot and test it.

Pretty much what @monk posted should work under any Linux distro.

@monk @nixcraft
This is an improvement, however the system now shows one of the following and although the user is automatically entered, a password is still requested.

Raspbian GNU/Linux 10 spilnx035 ttyS0
spilnx035 login: root (automatic login)
Password:

or

Raspbian GNU/Linux 10 spilnx035 ttyS0
spilnx035 login: pi (automatic login)
Password:

Depending on whether I configure it for user root or user pi. I tried the root user first but it did not work. I suspected because on Raspberry Pi OS no password is set for root so, I tried with the user pi.in doing so I replaced ‘root’ with ‘pi’ in the parameters and filenames mentioned in the directions.

My preference, if it is possible, is to have the ‘pi’ user automatically logged in and not ‘root’. Either method could be made to work however.

Tim

Good to know and yes pi is a better user. The following might give some clue if something is not working on your RPi:

systemctl status serial-getty@ttyS0.service
journalctl -u serial-getty@ttyS0.service

@monk @nixcraft

So now when the system boots I see this when the autologin occurs:

Raspbian GNU/Linux 10 spilnx035 ttyS0

spilnx035 login: pi (automatic login)


Last login: Fri Aug 20 15:16:12 CDT 2021 on ttyS0
Linux spilnx035 5.10.52-v7l+ #1441 SMP Tue Aug 3 18:11:56 BST 2021 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
-bash: cannot set terminal process group (623): Inappropriate ioctl for device
-bash: no job control in this shell
pi@spilnx035:~$ 

Raspbian GNU/Linux 10 spilnx035 ttyS0

spilnx035 login: pi
-bash: p: command not found
pi@spilnx035:~$ ls

Password: 

Login incorrect
spilnx035 login: 

-bash: s: command not found
pi@spilnx035:~$

At this point it seems as if ‘pi’ is automatically logged in but a second login prompt appears. It is not possible to actually login but it appears it is trying to manage two sessions on the same tty. I cannot enter any commands to debug things further at this point.

Tim

@monk @nixcraft

I have started with a fresh copy of my image taken before any of the autologin work began. I then applied the changes proposed by monk and the login process automatically supplies the user name pi. However, the password is not supplied automatically.

When I look at the status of the service there is a warning, but I don’t see what it refers to. It looks like the warning line is cutoff.

pi@spilnx035:~$ sudo systemctl status serial-getty@ttyS0.service
Warning: The unit file, source configuration file or drop-ins of serial-getty@tt
? serial-getty@ttyS0.service - Serial Getty on ttyS0
   Loaded: loaded (/lib/systemd/system/serial-getty@.service; enabled; vendor pr
  Drop-In: /etc/systemd/system/serial-getty@ttyS0.service.d
           mqoverride.conf
   Active: active (running) since Fri 2021-08-20 15:17:45 CDT; 20min ago
     Docs: man:agetty(8)
           man:systemd-getty-generator(8)
           http://0pointer.de/blog/projects/serial-console.html
 Main PID: 655 (login)
    Tasks: 0 (limit: 4915)
   CGroup: /system.slice/system-serial\x2dgetty.slice/serial-getty@ttyS0.service
           ? 655 /bin/login -p --

Aug 20 15:17:45 spilnx035 systemd[1]: Started Serial Getty on ttyS0.
Aug 20 15:17:52 spilnx035 login[655]: pam_unix(login:session): session opened fo
pi@spilnx035:~$

It seems as if the autologin is not working because the password is not being applied. This makes me suspicious of what we did in the /etc/pam.d/login file. The line I appended is:

auth sufficient pam_listfile.so item=tty sense=allow file=/etc/pittyloginfile onerr=fail apply=pi

@nixcraft @monk

First, I would like to thank people for the help and suggestions they provided. In the end, none of the suggestions ended up enabling autologin on my system.

I solved my problem by starting with a fresh installation of the operating system. On the first boot I immediately set the system to autologin at the console prompt using the raspi-config utility. That worked as I expected. Once I completed that step I went through my list of installation changes (fixed IP address, limiting ethernet speed to 100 Mb/s, enabling two extra serial ports, installing TFTP and NFS servers, etc.) and the system still automatically logs in when it boots up.

I have saved an image of the non working system and at some point hope to have time to try and figure out why the one didn’t work. For now the system is meeting its requirements and I need to move forward.

Tim

1 Like

Thanks for the update. I am still wondering why it didn’t work out for you? I might play with Raspberry PI and see what did I missed.

1 Like

Linux sysadmin blog - Linux/Unix Howtos and Tutorials - Linux bash shell scripting wiki