Linux – Could not load host key: /etc/ssh_host_*_key

linuxmacosssh

When doing this check:

$ /usr/sbin/sshd -t

Getting:

Could not load host key: /etc/ssh_host_rsa_key
Could not load host key: /etc/ssh_host_dsa_key

But when doing same check with sudo all is good:

$ sudo /usr/sbin/sshd -t
$

Does anyone know why does this happen, what’s wrong with my standard user and how to fix it?

Best Answer

Does anyone know why does this happen, what’s wrong with my standard user and how to fix it?

There is nothing wrong; you are attempting to run sshd (SSH daemon) as a non-privileged user.

For example, I am on Mac OS X 10.9.5 (Mavericks) and get the same exact “error” when running /usr/sbin/sshd -t:

Could not load host key: /etc/ssh_host_rsa_key
Could not load host key: /etc/ssh_host_dsa_key

Which is to be expected since sshd is the SSH daemon—note the d after ssh—that would run as a SSH server on the system listening and waiting for remote SSH login requests. So it would always need root/sudo permissions to work.

So this is not an “error” but rather expected behavior when attempting to run a system daemon like sshd as a non-privileged user.

Perhaps you are trying to run ssh -t? As the man page for the ssh -t option explains:

Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

Which basically allows you to run a command remotely from your current terminal and have the output displayed locally as if it ran on your local machine. So—as this page explains—if you wanted to run ls on a remote machine without actually fully logging in you could run this command:

ssh -t [username]@[hostname] ls

The output of ls would show up on your screen and the ssh connection would close immediately after that command completed.