Unlocking LUKS in initrd with systemd enabled through ssh

Is there an alternative to cryptsetup-askpass when systemd is enabled in initrd? I want to unlock root file system in SSH but that command is not available when systemd is enabled.
Also I am getting this error

Feb 15 19:25:21 localhost systemd[1]: Finished Cleanup udev Database.
Feb 15 19:26:51 localhost systemd[1]: dev-disk-by<snip>.device: Job dev-disk-by<snip>.device/start timed out.
Feb 15 19:26:51 localhost systemd[1]: Timed out waiting for device /dev/disk/by-uuid/<snip>.
Feb 15 19:26:51 localhost systemd[1]: Dependency failed for /sysroot.
Feb 15 19:26:51 localhost systemd[1]: Dependency failed for Initrd File Systems.
Feb 15 19:26:51 localhost systemd[1]: initrd-fs.target: Job initrd-fs.target/start failed with result 'dependency'.
Feb 15 19:26:51 localhost systemd[1]: initrd-fs.target: Triggering OnFailure= dependencies.
Feb 15 19:26:51 localhost systemd[1]: Dependency failed for /sysroot/nix.
Feb 15 19:26:51 localhost systemd[1]: sysroot-nix.mount: Job sysroot-nix.mount/start failed with result 'dependency'.
Feb 15 19:26:51 localhost systemd[1]: Dependency failed for /sysroot/var/log.
Feb 15 19:26:51 localhost systemd[1]: sysroot-var-log.mount: Job sysroot-var-log.mount/start failed with result 'dependency'.
Feb 15 19:26:51 localhost systemd[1]: sysroot.mount: Job sysroot.mount/start failed with result 'dependency'.
Feb 15 19:26:51 localhost systemd[1]: dev-disk-by<snip>.device: Job dev-disk-by<snip>.device/start failed with result 'timeout'.
Feb 15 19:26:51 localhost systemd[1]: Started Emergency Shell.
Feb 15 19:26:51 localhost systemd[1]: Reached target Emergency Mode.
Feb 15 19:26:51 localhost systemd[1]: Reached target Switch Root.
Feb 15 19:26:51 localhost systemd[1]: Starting Switch Root...
Feb 15 19:26:51 localhost systemd[1]: panic-on-fail.service was skipped because no trigger condition checks were met.
Feb 15 19:26:51 localhost @ystemctl[258]: Failed to switch root: Failed to determine whether root path '/sysroot' contains an OS tree: No such file or directory
Feb 15 19:26:51 localhost systemd[1]: initrd-switch-root.service: Main process exited, code=exited, status=1/FAILURE
Feb 15 19:26:51 localhost systemd[1]: initrd-switch-root.service: Failed with result 'exit-code'.
Feb 15 19:26:51 localhost systemd[1]: Failed to start Switch Root.

Is there a way to increase the timeout?

systemd-tty-ask-password-agent is the command you’re looking for. Or, what I actually do is just systemctl default, which will run said agent implicitly until the default target is reached.

As for the timeout, this is sort of a sore spot with systemd initrd at the moment, but it is fixable. The problem is that systemd-cryptsetup-generator doesn’t know that /dev/mapper/foo is going to be the same thing as /dev/disk/by-....., so it isn’t able to configure the /dev/disk/by-..... device unit to be ordered after the systemd-cryptsetup@foo.service unit, so it times out waiting for the device instead of just waiting for cryptsetup to finish first.

You can fix this either by using /dev/mapper/foo as your device instead of /dev/disk/by-....., or if that’s not possible because you have LVM or something on top of it, you can just use the x-systemd.device-timeout= file system option to increase the timeout or I think you can set it to infinity or 0 to make it indefinite. Or you can manually configure some systemd unit options to get the ordering correct between device units / services.

I was able to unlock the root by using either systemd-tty-ask-password-agent or systemctl default and I haven’t seen a timeout in the log since I updated it to /dev/mapper/<name>