RHEL/CentOS 7 SSH Hardening

Description

Hardening the configuration of the SSH server is an important step in hardening your server. We recommend that you harden SSH as described below.

Relevant to

  • CentOS 7.x or RHEL 7.x - all versions

Prerequisites

TOS must be installed on the server prior to implementing this resolution.

Notes

You will have to restart the sshd service after making the recommended changes. The service restart is included in the resolution steps below.

Resolution

  1. Edit the file /etc/ssh/sshd_config, and set the fields listed below to the values listed. You may have to delete the comment character ('#') from some entries.

    X11Forwarding no
    Banner /etc/banner
    ClientAliveInterval 3600
    ClientAliveCountMax 0
    AllowAgentForwarding no
    AllowTcpForwarding no

  2. In the file /etc/ssh/sshd_config, if the setting KexAlgorithms exists, remove the value diffie-hellman-group1-sha1 and add the following values:

    diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha256

  3. In the file /etc/ssh/sshd_config, if the setting KexAlgorithms did not exist, add the setting KexAlgorithms with the following value:

    KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha256

  4. Restart the sshd service:

    # systemctl restart sshd

  5. Install all official security patches and updates released by the Linux distribution.