--- - name: Disable AllowAgentForwarding ansible.builtin.lineinfile: path: /etc/ssh/sshd_config regexp: '^#?AllowAgentForwarding' line: 'AllowAgentForwarding no' validate: "sshd -t -f %s" notify: Restart sshd - name: Disable ChallengeResponseAuthentication ansible.builtin.lineinfile: path: /etc/ssh/sshd_config regexp: '^#?ChallengeResponseAuthentication' line: 'ChallengeResponseAuthentication no' validate: "sshd -t -f %s" notify: Restart sshd # based on mozilla recommended settings # https://infosec.mozilla.org/guidelines/openssh.html # # * prefer aes over chacha for hardware acceleration # * use only ed25519 host key # - name: Disable default crypto policy ansible.builtin.lineinfile: path: /etc/sysconfig/sshd regexp: '^(#\s+)?CRYPTO_POLICY=' line: "CRYPTO_POLICY=" notify: Restart sshd when: - ansible_distribution == "Rocky" - ansible_distribution_version | int == 8 - name: Tighten ssh kex algorithm ansible.builtin.lineinfile: path: /etc/ssh/sshd_config line: "KexAlgorithms curve25519-sha256@libssh.org,\ diffie-hellman-group-exchange-sha256" regexp: "^KexAlgorithms .*" validate: "sshd -t -f %s" notify: Restart sshd - name: Tighten sshd ciphers ansible.builtin.lineinfile: path: /etc/ssh/sshd_config line: "Ciphers aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,\ aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr" regexp: "^Ciphers .*" validate: "sshd -t -f %s" notify: Restart sshd - name: Tighten sshd macs ansible.builtin.lineinfile: path: /etc/ssh/sshd_config line: "MACs hmac-sha2-512-etm@openssh.com,\ hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,\ hmac-sha2-512,hmac-sha2-256,umac-128@openssh.com" regexp: "^MACs .*" validate: "sshd -t -f %s" notify: Restart sshd - name: Disable ECDSA key from sshd ansible.builtin.lineinfile: path: /etc/ssh/sshd_config line: "#HostKey /etc/ssh/ssh_host_ecdsa_key" regexp: "^#?HostKey /etc/ssh/ssh_host_ecdsa_key" validate: "sshd -t -f %s" notify: Restart sshd - name: Disable RSA key from sshd ansible.builtin.lineinfile: path: /etc/ssh/sshd_config line: "#HostKey /etc/ssh/ssh_host_rsa_key" regexp: "^#?HostKey /etc/ssh/ssh_host_rsa_key" validate: "sshd -t -f %s" notify: Restart sshd - name: Enable ed25519 key from sshd ansible.builtin.lineinfile: path: /etc/ssh/sshd_config line: "HostKey /etc/ssh/ssh_host_ed25519_key" regexp: "^#?HostKey /etc/ssh/ssh_host_ed25519_key" validate: "sshd -t -f %s" notify: Restart sshd