The sshd
service by default calls sshd-keygen.target
, which checks availability of host keys in /etc/ssh
directory and generates it when missing.
However this well known functionality can be blocked by the new version of cloud-init
. As of cloud-init-22.1-5.el8.noarch
there is new file:
/etc/systemd/system/[email protected]/disable-sshd-keygen-if-cloud-init-active.conf
with content:
# In some cloud-init enabled images the sshd-keygen template service may race
# with cloud-init during boot causing issues with host key generation. This
# drop-in config adds a condition to [email protected] if it exists and
# prevents the sshd-keygen units from running *if* cloud-init is going to run.
#
[Unit]
ConditionPathExists=!/run/systemd/generator.early/multi-user.target.wants/cloud-init.target
So when you use the cloud-init
you have 2 options now:
- Generate host keys manually with
ssh-keygen -A
(see How to change a SSH host key? for more details and options.
- Comment the condition
Simply put the #
sign before ConditionPathExists...
[Unit]
#ConditionPathExists=!/run/systemd/generator.early/multi-user.target.wants/cloud-init.target
Then reload the systemd configuration with systemctl daemon-reload
. The usual behavior should be working again.