[How to solve] Could not load host key: /etc/ssh/ssh_host_rsa_key issue in FreeBSD or Linux

[How to solve] Could not load host key: /etc/ssh/ssh_host_rsa_key issue in FreeBSD or Linux

 

This post was last updated on October 15th, 2020 at 01:55 am

Once I was strating the sshd service, I saw the error: Could not load host key: /etc/ssh/ssh_host_rsa_key issue.

Sometimes while starting the sshd service you may face some issues like the following:
Could not load host key: /etc/ssh/ssh_host_key
Could not load host key: /etc/ssh/ssh_host_rsa_key
Could not load host key: /etc/ssh/ssh_host_dsa_key
Could not load host key: /etc/ssh/ssh_host_ecdsa_key
Disabling protocol version 2. Could not load host key
sshd: no hostkeys available -- exiting.

Usually, these ssh security keys should have been created during the ssh installation itself. But unfortunately, if it is not mentioned to create these files automatically in the sshd configuration file, then you will definitely miss the keys and without these host keys the sshd service will not start.

Well, in such case either you set the corresponding sshd configuration file and restart the sshd service or restart your Linux or FreeBSD system so that these host keys can be generated manually.

Personally, I would suggest you to create these keys manually because finding the sshd configuration file is another overhead task because different systems have their sshd configuration files at different places.

How to create sshd keys to solve Could not load host key: /etc/ssh/ssh_host_rsa_key issue?

If ssh commands are already installed in your system then you can just execute the below command to create the keys manually:
ssh-keygen -A
OR
ssh-keygen -b 1024 -t rsa -f /etc/ssh/ssh_host_key
ssh-keygen -b 1024 -t rsa -f /etc/ssh/ssh_host_rsa_key
ssh-keygen -b 1024 -t dsa -f /etc/ssh/ssh_host_dsa_key
ssh-keygen -b 1024 -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key

The first command will automatically generate all the required keys. But the second command will be helpful if you want to create only one of those keys and not all.

But I really do not see any difference of using the second step because the ssh-keygen -A will take care of creating the ssh keys for which there is no key has been generated yet.

In the second command the -b 1024 option specifies the key will be of 1024 bit length, and the -t option specifies the type of key: either rsa, dsa or ecdsa.

Troubleshooting:

Sometimes the ssh is not at all installed on your system or you missed out to enable the ssh package while installing the OS. How you will come to know if ssh is installed or not?? just type ssh in your command prompt and to surprise you will see that command is not found or similar text.

Well, in such case you just see how to install a package in your system.
For example:
sudo apt-get install openssh-server should work in Ubuntu Linux
pkg install ssh or pkg install openssh should work In FreeBSD.

Well I think this will mostly help you out to solve Could not load host key: /etc/ssh/ssh_host_rsa_key issue. If not then comment in the comment box and I will surely help you out.

Previous How to Unload or Blacklist Module in Linux
Next [FreeBSD] How to allow Root access on FreeBSD over ssh protocol
 

About author

Sibananda Sahu
Sibananda Sahu 207 posts

A Linux Kernel Developer and a Firmware Developer by profession. Have worked with few big companies: BROADCOM Corporation, Cypress Semiconductor, LSI Corporation, TOSHIBA Corporation, Western Digital; on various cutting edge technologies and product lines, such as: RAID storage Driver, SSD Firmware, WLAN Firmware etc. Having more than 9 years of experience in Software Engineering domain. Now, took a pledge to educate all aspirant students to teach about Linux Kernel Development.

View all posts by this author →

You might also like

FreeBSD 0 Comments

[FreeBSD] How to set and unset loader variables in boot loader prompt

This post was last updated on February 17th, 2019 at 06:08 amImportant question is why you need to set and unset variables at boot time???The answer is when something is

FreeBSD 0 Comments

How To Install And Configure Xfce In FreeBSD?

This post was last updated on August 1st, 2020 at 10:30 amXfce is a free and opensource desktop environment that aims to be lightweight, fast, and low on system resources

FreeBSD 0 Comments

[FreeBSD] How to Install FreeBSD OS, Step by step guide using a virtual machine

This post was last updated on July 21st, 2020 at 01:15 pmTake a deep breathe and be sure that you have at least an hour of time. We have to

1 Comment

  1. Hittu
    April 08, 12:13 Reply

    Hi,

    I was also facing similar issues. I tried to generate keys using ssh-keygen -A but facing the below error. Doesn’t allow to touch the file:-

    ssh-keygen -A

    ssh-keygen: generating new host keys: RSA1 Saving key “/etc/ssh/ssh_host_key” failed: No such file or directory
    ssh-keygen: generating new host keys: RSA Saving key “/etc/ssh/ssh_host_rsa_key” failed: No such file or directory
    ssh-keygen: generating new host keys: DSA Saving key “/etc/ssh/ssh_host_dsa_key” failed: No such file or directory
    ssh-keygen: generating new host keys: ECDSA Saving key “/etc/ssh/ssh_host_ecdsa_key” failed: No such file or directory
    ssh-keygen: generating new host keys: ED25519 Saving key “/etc/ssh/ssh_host_ed25519_key” failed: No such file or directory

    Anyhelp is appreciated,

    Thanks,
    Hittu

Leave a Reply