Boot into rescue mode with disabled root account

If you need to get a root shell on a NixOS[1] machine and the root account is disabled/locked (and/or you’ve forgotten all your passwords), here’s how to do it (without booting a live ISO).

When the machine boots, interrupt the bootloader and add this to the bootloader command-line:

[...] rescue systemd.setenv=SYSTEMD_SULOGIN_FORCE=1

(Without SYSTEMD_SULOGIN_FORCE=1 you will not be able to get a shell if the root account is disabled/locked.)

Ref. sulogin-shell: Use force if SYSTEMD_SULOGIN_FORCE set · systemd/systemd@33eb44f · GitHub

[1]: Or any GNU/Linux distro really.

1 Like