2

Scenario

I'm trying to bootstrap Raspberry Pi's by just putting configuration to the "boot"-volume.

My workflow looks like this:

  1. Flash SD-card with Raspberry Pi OS Lite
  2. copy these files to "boot"-volume on SD-card:
    • config.txt (configure HDMI-mode and similar)
    • ssh (enable ssh-server)
    • userconf.txt (create a user)
    • wpa_supplicant.conf (my wifi configuration)
  3. use ssh-copy-id to copy ssh-keys
  4. do further configuration with Ansible

The file userconf.txt will create a user as described here: https://www.raspberrypi.com/documentation/computers/configuration.html#configuring-a-user

Content of userconf.txt:

username:$6$nbLUJeL0WK93K6Sw$CfT59XqmEMyzIszjeNbvTdvkDn0VUV0iYu9xNuoasBePtJl5b.yJY3bbGpCuaTEJartPOpLZvcRi02MOYj7Qv.

Unfortunately this user is a auto-login user, even on the CLI (e.g. on a Raspberry Pi OS Lite).

Question:

Is there a way to disable the auto-login feature via some entry in config.txt or userconf.txt?

I am not talking about /etc/lightdm.conf, I'm talking about the Linux shell.

2 Answers 2

1

[The first bit here is mostly to acknowledge the mistake I made in my original answer:] If you don't want to use autologin at all, check systemctl status autologin. If it is indeed in use:

sudo systemctl mask autologin

This links the service to /dev/null so even if it is enabled it will do nothing. However: I have this on at least one of my Pi's, but I do not remember why, and I notice that systemctl mask whatever.service will create this symlink even if "whatever.service" does not exist, and there is no autologin.service in /lib/systemd, which is where all system service files are, enabled or not. So this is probably a red herring of mine.

You can enable and disable login both for the console and the GUI with raspi-config. WRT the console, what it does is write an autologin.conf to /etc/systemd/system/[email protected]. The getty service starts getty instances (see man getty) on the console ttys.

Following up on that, I learned something new about systemd; this is from man 5 systemd.unit:

Along with a unit file foo.service, a "drop-in" directory foo.service.d/ may exist. All files with the suffix ".conf" from this directory will be merged in the alphanumeric order and parsed after the main unit file itself has been parsed. This is useful to alter or add configuration settings for a unit, without having to modify unit files.

To disable this, raspi-config simply deletes the file. If you want to permanently ensure it cannot be enabled again, use the same trick as systemctl mask described above (have a look at man ln if you are unfamiliar with what that does):

sudo ln -s /dev/null /etc/systemd/system/[email protected]/autologin.conf

You'll have to delete the original autologin.conf first if it exists. Raspi-config creates that file by redirecting output from cat. If you do that to such an existing symlink, whatever is written to the file just disappears (this likely explains why systemctl mask can be applied to a non-existent service -- this way, if it is ever installed on the system, it should end up masked).

4
  • Thank you very much for this information.
    – ppuschmann
    Nov 20, 2022 at 20:22
  • I only wonder if this is achieveable with "Raspberry Pi OS" tooling
    – ppuschmann
    Nov 20, 2022 at 20:30
  • You can enable and disable autologin with raspi-config. AFAICT it doesn't actually use the service I refer to (did disabling this actually work for you?) -- I'll edit some more information in about that...
    – goldilocks
    Nov 21, 2022 at 14:36
  • Thank you very much for the thorough answer and the edits. I now also fired up my RasPi and used "etckeeper" to find out about the deletion of "/etc/systemd/system/[email protected]/autologin.conf"
    – ppuschmann
    Nov 23, 2022 at 21:24
0

Raspberry Pi OS default is to login as default user. (autologin is not normally used autologin.service could not be found).

Normally Login preferences (one of 4 options; 2 valid for Lite) are set in the System Options menu of raspi-config.

This normally applies to the default user (uid=1000).

The id command prints details for a user.

2
  • I'm sorry, but this doesn't really answer my question and gives no real hint how to turn this off.
    – ppuschmann
    Nov 23, 2022 at 21:28
  • It does answer (one of your questions) which is to use raspi-config which is the NORMAL procedure. I have added a link to the official documentation.
    – Milliways
    Nov 23, 2022 at 23:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.