Verify Permissions on SSH Server Private *_key Key Files
An XCCDF Rule
Description
SSH server private keys - files that match the /etc/ssh/*_key
glob, have to have restricted permissions.
If those files are owned by the root
user and the root
group, they have to have the 0640
permission or stricter.
Rationale
If an unauthorized user obtains the private SSH host key file, the host could be impersonated.
- ID
- xccdf_org.ssgproject.content_rule_file_permissions_sshd_private_key
- Severity
- Medium
- References
- Updated
Remediation - Shell Script
# Remediation is applicable only in certain platforms
if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then
for keyfile in /etc/ssh/*_key; do
test -f "$keyfile" || continue
if test root:root = "$(stat -c "%U:%G" "$keyfile")"; then
Remediation - Ansible
- name: Find root:root-owned keys
ansible.builtin.command: find -H /etc/ssh/ -maxdepth 1 -user root -regex ".*_key$"
-type f -group root -perm /u+xs,g+xws,o+xwrt
register: root_owned_keys
changed_when: false
failed_when: false
Remediation - Puppet
include ssh_private_key_perms
class ssh_private_key_perms {
exec { 'sshd_priv_key':
command => "chmod 0640 /etc/ssh/*_key",
path => '/bin:/usr/bin'