Information
An SSH private key is one of two files used in SSH public key authentication. In this authentication method, the possession of the private key is proof of identity. Only a private key that corresponds to a public key will be able to authenticate successfully. The private keys need to be stored and handled carefully, and no copies of the private key should be distributed.
If an threat actor obtains the private SSH host key file, the host could be impersonated.
Solution
Update the access to the private keys being used by the open SSH server.
- mode to 0600.
- owner to the user root.
- group owner to the group root.
Run the following script to update the access on the private keys used by the open SSH server:
#!/usr/bin/env bash
{
l_sshd_cmd=\"$(readlink -e /usr/sbin/sshd || readlink -e /sbin/sshd)\"
l_keygen=\"$(readlink -e /usr/bin/ssh-keygen || readlink -e /bin/ssh-keygen)\"
while IFS= read -r l_file; do
if \"$l_keygen\" -lf &>/dev/null \"$l_file\"; then
chown root:root \"$l_file\"
chmod 0600 \"$l_file\"
done < <(\"$l_sshd_cmd\" -T | awk '$1==\"hostkey\" {print $2\".pub\"}' 2>/dev/null)
}
Impact:
If the private keys used by the openSSH server have the incorrect mode, owner, or group owner the server service may not start.