WebHosting

Monday, June 29, 2026

Fixing “sshd: no hostkeys available -- exiting” in Ubuntu (VMware / Cloned VM)



If you’re trying to start SSH on Ubuntu and encounter this error:

sshd: no hostkeys available -- exiting.

Don’t worry — this is a common issue, especially when working with cloned virtual machines or golden images.

In this guide, we’ll break down:

  • ✅ What this error means
  • 🔍 Why it happens
  • ⚙️ Step-by-step fix
  • 🧠 Best practices for future

🚨 What Does This Error Mean?

SSH (Secure Shell) requires host keys to identify the server securely.

These keys are stored in:

/etc/ssh/ssh_host_*

If these keys are missing, SSH cannot start — resulting in:

sshd: no hostkeys available -- exiting.

🔍 Why This Happens

This issue typically occurs in these scenarios:

🧩 1. Cloned Virtual Machines

When you clone a VM, you may remove host keys intentionally to avoid duplication.

🧹 2. Golden Image Preparation

During template creation, admins often delete SSH keys for security reasons.

⚠️ 3. Manual Deletion or Misconfiguration

Accidental removal of /etc/ssh/ssh_host_* files.


⚙️ Step-by-Step Fix

🔹 Step 1: Generate New Host Keys

Run the following command:

sudo ssh-keygen -A

This will generate all required SSH host keys automatically.


🔹 Step 2: Restart SSH Service

sudo systemctl restart ssh

🔹 Step 3: Verify SSH Status

sudo systemctl status ssh

You should now see:

active (running)

🔹 Step 4: Confirm SSH is Listening

ss -tulnp | grep :22

If everything is working, SSH should be listening on port 22.


🔐 Test SSH Connection

From your host machine:

ssh username@your-ip-address

Example:

ssh shashwat@192.168.59.18

🧠 Best Practices (Important)

If you’re working with VMs, templates, or automation:

✅ Always regenerate SSH keys after cloning

sudo ssh-keygen -A

✅ Use cloud-init (Advanced)

Automate:

  • Hostname
  • SSH keys
  • Network config

✅ Never reuse SSH host keys across machines

This can lead to:

  • Security risks
  • SSH warnings
  • Connection issues

🎯 Summary

IssueFix
SSH not startingGenerate host keys
Error: no hostkeys availablesudo ssh-keygen -A
Service failingRestart SSH

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

Fixing “sshd: no hostkeys available -- exiting” in Ubuntu (VMware / Cloned VM)

If you’re trying to start SSH on Ubuntu and encounter this error: sshd: no hostkeys available -- exiting. Don’t worry — this is a common ...