Information
An SSH public key is one of two files used in SSH public key authentication. In this authentication method, a public key is a key that can be used for verifying digital signatures generated using a corresponding private key. Only a public key that corresponds to a private key will be able to authenticate successfully.
If a public host key file is modified by an unauthorized user, the SSH service may be compromised.
Solution
Run the following script to set the owner, group, and restrict permissions on each SSH public host key file from the running sshd configuration:
#!/usr/bin/env bash
{
while IFS= read -r l_key; do
l_file="${l_key}.pub"
[ -e "$l_file" ] || continue
chown root:root "$l_file"
chmod u-x,go-wx "$l_file"
done < <(sshd -T 2>/dev/null | awk '$1=="hostkey"{print $2}')
}
Impact:
Public host key files are intended to be readable; enforcing mode 0644, owner and group root, only removes excess write and execute permissions and does not affect normal SSH operation.