Verify Permissions on SSH Server Public *.pub Key Files
An XCCDF Rule
Description
To properly set the permissions of /etc/ssh/*.pub
, run the command:
$ sudo chmod 0644 /etc/ssh/*.pub
Rationale
If a public host key file is modified by an unauthorized user, the SSH service may be compromised.
- ID
- xccdf_org.ssgproject.content_rule_file_permissions_sshd_pub_key
- Severity
- Medium
- References
- Updated
Remediation - Ansible
- name: Find /etc/ssh/ file(s)
command: find -H /etc/ssh/ -maxdepth 1 -perm /u+xs,g+xws,o+xwt -type f -regex "^.*\.pub$"
register: files_found
changed_when: false
failed_when: false
check_mode: false
Remediation - Puppet
include ssh_public_key_perms
class ssh_public_key_perms {
exec { 'sshd_pub_key':
command => "chmod 0644 /etc/ssh/*.pub",
path => '/bin:/usr/bin'
Remediation - Shell Script
# Remediation is applicable only in certain platforms
if [ ! -f /.dockerenv ] && [ ! -f /run/.containerenv ]; then
find -H /etc/ssh/ -maxdepth 1 -perm /u+xs,g+xws,o+xwt -type f -regex '^.*\.pub$' -exec chmod u-xs,g-xws,o-xwt {} \;
else