Published

Configuring Autologin on TTY

Generally automatic login is security risk. But there are some situations where it makes sense, such as when running a VM or LXC container on a single-user host machine. In this case the user is already authenticated by nature of having access to VM or container's TTY and the need to type in a password is really just a hindrance.

Alpine

Ref: https://wiki.alpinelinux.org/wiki/TTY_Autologin

Standard Alpine still uses the inittab configuration file. Install agetty(8) and then update inittab.

/etc/inittab:

tty1::respawn:/sbin/agetty --autologin root tty1 linux

Note: If you are using Alpine minimal root inside a LXC container, this can be done by modifying root filesystem before starting the container. It's also a good time to remove or comment out the extra TTY services as otherwise the default TTY will be almost unusable due to warning messages about non-existent devices.

Fedora

Ref: https://unix.stackexchange.com/a/552642

On Fedora, autologin still prompts for a password. To get a true automatic login, PAM must be configured to treat all login attempts from the given TTY device as authenticated. See pam.conf(5) and pam_listfile(8) for more information.

/etc/pam.d/login:

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

Populate the file listed above with the desired TTY device. You can find this by logging in to the TTY and running the tty(1) command.

/etc/securetty:

/dev/tty1

Finally configure the agetty(8) systemd unit with the --autologin flag using a drop-in configuration file:

/etc/systemd/system/getty@tty1.service.d/override.conf:

[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin root -o '-p -- \\u' --noclear - $TERM

More...

I'll keep this updated as I run into this issue on other distros.