id: os_sshd_client_alive_count_max_configure
title: Configure SSHD ClientAliveCountMax to $ODV
discussion: |
  If SSHD is enabled it _MUST_ be configured with the Client Alive Maximum Count set to $ODV.

  This will set the number of client alive messages which may be sent without the SSH server receiving any messages back from the client.  If this threshold is reached while client alive messages are being sent, the SSH server will disconnect the client, terminating the session.  The client alive messages are sent through the encrypted channel and therefore will not be spoofable.  The client alive mechanism is valuable when the client or server depend on knowing when a connection has become unresponsive.

  NOTE: This setting is not intended to manage idle user sessions where there is no input from the client. Its purpose is to monitor for interruptions in network connectivity and force the session to terminate after the connection appears to be broken.

  NOTE: On macOS 15.2 and higher the SSH configuration can be reset to the macOS default by running /usr/libexec/reset-ssh-configuration.
check: |
  /usr/sbin/sshd -G | /usr/bin/awk '/clientalivecountmax/{print $2}'
result:
  integer: $ODV
fix: |
  [source,bash]
  ----
  include_dir=$(/usr/bin/awk '/^Include/ {print $2}' /etc/ssh/sshd_config | /usr/bin/tr -d '*')

  if [[ -z $include_dir ]]; then
    /usr/bin/sed -i.bk "1s/.*/Include \/etc\/ssh\/sshd_config.d\/\*/" /etc/ssh/sshd_config
  fi

  /usr/bin/grep -qxF 'clientalivecountmax $ODV' "${include_dir}01-mscp-sshd.conf" 2>/dev/null || echo "clientalivecountmax $ODV" >> "${include_dir}01-mscp-sshd.conf"

  for file in $(ls ${include_dir}); do
    if [[ "$file" == "100-macos.conf" ]]; then
        continue
    fi
    if [[ "$file" == "01-mscp-sshd.conf" ]]; then
        break
    fi
    /bin/mv ${include_dir}${file} ${include_dir}20-${file}
  done
  ----
references:
  cce:
    - CCE-95308-3
  cci:
    - CCI-001133
  800-53r5:
    - SC-10
  800-53r4:
    - SC-10
  srg:
    - SRG-OS-000163-GPOS-00072
  disa_stig:
    - APPL-26-000052
  800-171r3:
    - 03.13.09
  cmmc:
    - SC.L2-3.13.9
macOS:
  - '26.0'
odv:
  hint: Number of seconds.
  recommended: 0
  stig: 1
tags:
  - 800-53r5_moderate
  - 800-53r5_high
  - 800-53r4_moderate
  - 800-53r4_high
  - 800-171
  - cnssi-1253_low
  - cnssi-1253_high
  - cmmc_lvl2
  - stig
  - cnssi-1253_moderate
severity: medium
mobileconfig: false
mobileconfig_info:
ddm_info:
  declarationtype: com.apple.configuration.services.configuration-files
  service: com.apple.sshd
  config_file: sshd_config
  configuration_key: ClientAliveCountMax
  configuration_value: $ODV