How to fix sshd: no hostkeys available -- exiting. in SSH

SSHBEGINNERCRITICALUpdated Oct 2, 2026· 762 views

The SSH daemon (sshd) cannot start because it cannot find or access its host keys. Host keys are cryptographic credentials that identify the SSH server to clients, and they must exist and be accessible for sshd to operate. This error typically occurs after a fresh installation, accidental deletion, or permission changes that prevent sshd from reading the keys.

Quick fix

Fixes sshd: no hostkeys available -- exiting.

ls -la /etc/ssh/ssh_host_*key*
  1. Check if host key files exist
  2. Generate missing host keys
  3. Fix file permissions
  4. Verify sshd_config references the correct paths
ssh — error
ls -la /etc/ssh/ssh_host_*key*
sshd: no hostkeys available -- exiting.

What this error means

SSH host keys are essential cryptographic files stored on your server (usually in /etc/ssh/) that allow the SSH daemon to identify itself to connecting clients and establish encrypted connections. When sshd starts, it immediately looks for these host keys in the locations specified by its configuration file (sshd_config). If no host keys exist at the configured paths or if the files are not readable due to permission issues, sshd exits with this error rather than starting with inadequate security. This prevents insecure SSH connections and protects against potential security misconfigurations.

Typical symptoms

  • SSH service fails to start with 'no hostkeys available' message
  • Cannot SSH into the server at all (connection refused)
  • systemctl status sshd shows inactive status
  • journalctl logs show the exact error: 'sshd: no hostkeys available -- exiting.'
  • Error occurs immediately after system installation or fresh OS deployment
  • SSH was working, then stopped after filesystem or permissions changes

Common causes

  1. Host key files were never generated during system installation
  2. Host key files were accidentally deleted or corrupted
  3. SSH configuration file (sshd_config) points to non-existent key locations
  4. File permissions on host key files prevent sshd from reading them (too restrictive)
  5. File permissions on /etc/ssh directory prevent access to host key files
  6. Filesystem containing /etc/ssh is corrupted or unmounted
  7. Host keys exist but sshd_config is misconfigured or commented out
  8. Fresh container or VM image without SSH initialization completed

How to fix "sshd: no hostkeys available -- exiting."

1Check if host key files exist

First, verify whether the host key files actually exist on your system:

bash
ls -la /etc/ssh/ssh_host_*key*

You should see output like:
- ssh_host_rsa_key (private, mode 600)
- ssh_host_ecdsa_key (private, mode 600)
- ssh_host_ed25519_key (private, mode 600)
- ssh_host_*_key.pub files (public, mode 644)

If these files don't exist at all, proceed to Step 2. If they exist but show wrong permissions, skip to Step 3.

2Generate missing host keys

If the host key files don't exist, generate them using ssh-keygen:

Option A: Generate all default keys at once (recommended)

bash
sudo ssh-keygen -A

This command automatically generates all missing key types (RSA, ECDSA, ED25519) in their standard locations.

Option B: Generate individual key types manually

bash
sudo ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ""
sudo ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N ""
sudo ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""

The -N "" flag means "no passphrase" (required for host keys).

After generation, verify the files exist:

bash
ls -la /etc/ssh/ssh_host_*key*
3Fix file permissions

Host key permissions must be:
- Private keys (ssh_host_*_key): 600 (readable only by root)
- Public keys (ssh_host_*_key.pub): 644 (world-readable)

Fix permissions with:

bash
sudo chmod 600 /etc/ssh/ssh_host_*_key
sudo chmod 644 /etc/ssh/ssh_host_*_key.pub

Verify the result:

bash
ls -la /etc/ssh/ssh_host_*

Private keys should show -rw------- (600) and public keys -rw-r--r-- (644).

Ensure ownership is correct (should be root):

bash
sudo chown root:root /etc/ssh/ssh_host_*
4Verify sshd_config references the correct paths

Open your SSH configuration file and verify the HostKey directives point to the correct locations:

bash
sudo grep -n "^HostKey" /etc/ssh/sshd_config

You should see entries like:

bash
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

If these lines are missing or commented out (start with #), add or uncomment them:

bash
sudo nano /etc/ssh/sshd_config

Ensure these lines are present and uncommented:

bash
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key

Save and exit (Ctrl+O, Enter, Ctrl+X in nano).

5Restart SSH service

After generating keys and fixing permissions, restart the SSH daemon:

On systemd systems (most modern Linux):

bash
sudo systemctl restart sshd

Verify it's running:

bash
sudo systemctl status sshd

On older init systems:

bash
sudo service ssh restart

Check for errors in logs:

bash
sudo journalctl -xe -u sshd | tail -20

If you see "sshd: no hostkeys available" still, check the previous steps. If you see a different error, record that error message for further troubleshooting.

6Test SSH connection

Verify SSH is now working:

bash
ssh -v localhost

Or from another machine:

bash
ssh username@your-server-ip

If connection succeeds, the issue is resolved. If you get a different error (e.g., "Connection refused"), the host keys are working but another issue exists (firewall, port binding, etc.).

7Regenerate on Debian/Ubuntu (alternative method)

On Debian/Ubuntu systems, you can use dpkg to regenerate SSH keys:

bash
sudo rm /etc/ssh/ssh_host_*
sudo dpkg-reconfigure openssh-server

This removes the old keys and lets the openssh-server package regenerate them during reconfiguration. It's safe to run over an existing SSH session—your current connection won't be interrupted.

After reconfiguration, check that new keys were generated:

bash
ls -la /etc/ssh/ssh_host_*key*

Advanced notes

Advanced troubleshooting:

Containerized deployments: When building Docker images or VMs, SSH host keys should be generated during image creation or at first boot (not committed to the image itself, as each instance needs unique keys). Use an entrypoint script:

bash
#!/bin/bash
if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
  ssh-keygen -A
fi
exec /usr/sbin/sshd -D

Cloud provider gotchas: AWS, Azure, and GCP run initialization scripts that generate host keys automatically on first boot. If you see this error on a cloud instance, the initialization script may have failed. Check cloud-init logs:

bash
cloud-init status
cat /var/log/cloud-init-output.log

SELinux/AppArmor issues: On systems with mandatory access controls, wrong SELinux contexts or AppArmor profiles can prevent sshd from accessing key files even if permissions look correct. Check:

bash
# SELinux systems
getenforce
restorecon -Rv /etc/ssh/

# AppArmor systems
sudo systemctl status apparmor

Filesystem issues: If /etc/ssh/ is on a read-only mounted filesystem or network mount with caching issues, sshd cannot read keys. Verify:

bash
mount | grep "/etc/ssh"
touch /etc/ssh/.test_write  # Try writing a test file

Debugging with verbose sshd: Run sshd in debug mode to see exactly which paths it's looking for:

bash
sudo /usr/sbin/sshd -ddd  # (don't do this on production while listening on port 22)

Frequently asked questions

What does "sshd: no hostkeys available -- exiting." mean?
SSH host keys are essential cryptographic files stored on your server (usually in /etc/ssh/) that allow the SSH daemon to identify itself to connecting clients and establish encrypted connections. When sshd starts, it immediately looks for these host keys in the locations specified by its configuration file (sshd_config). If no host keys exist at the configured paths or if the files are not readable due to permission issues, sshd exits with this error rather than starting with inadequate security.
How do I fix "sshd: no hostkeys available -- exiting."?
The SSH daemon (sshd) cannot start because it cannot find or access its host keys. Host keys are cryptographic credentials that identify the SSH server to clients, and they must exist and be accessible for sshd to operate. This error typically occurs after a fresh installation, accidental deletion, or permission changes that prevent sshd from reading the keys.
What causes "sshd: no hostkeys available -- exiting."?
Host key files were never generated during system installation Host key files were accidentally deleted or corrupted SSH configuration file (sshd_config) points to non-existent key locations
Is the "sshd: no hostkeys available -- exiting." error serious?
Yes. This is a critical-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading