To configure auto-login for a systemd-nspawn container, override console-getty.service:
# /etc/systemd/system/console-getty.service.d/override.conf [Service] ExecStart= ExecStart=-/sbin/agetty --noclear --autologin username --keep-baud console 115200,38400,9600 $TERM
If
machinectl login my-containermethod is used to access the container, also add--autologin USERNAMEto[email protected]template that managespts/[0-9]pseudo ttys:
# /etc/systemd/system/[email protected]/override.conf [Service] ExecStart= ExecStart=-/sbin/agetty --noclear --autologin username --keep-baud pts/%I 115200,38400,9600 $TERM
I've used this in practice for nsbox, and it's worked quite well with one catch: agetty will also proceed to start a shell, thus your bashrc/zshrc will be run and you may have an ugly prompt printed to the console that ran nspawn. Not a deal breaker but something worth noting...