id: os_sshd_client_alive_interval_configure
title: Configure SSHD ClientAliveInterval to $ODV
discussion: |
  If SSHD is enabled then it _MUST_ be configured with the Client Alive Interval set to $ODV.

  Sets a timeout interval in seconds after which if no data has been received from the client, sshd(8) will send a message through the encrypted channel to request a response from the client.

  This setting works in conjunction with ClientAliveCountMax to determine the termination of the connection after the threshold has been reached.

  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. Previous versions of macOS would revert /etc/ssh/sshd_config to its original state following any update or major upgrade to the operating system.
references:
  nist:
    cce:
      macos_27:
        - CCE-XXXXX-X
      macos_26:
        - CCE-95309-1
      macos_15:
        - CCE-94304-3
      macos_14:
        - CCE-92899-4
    800-53r5:
      - SC-10
      - AC-12
    800-171r3:
      - 03.01.11
      - 03.13.09
  disa:
    cci:
      - CCI-001133
    srg:
      - SRG-OS-000163-GPOS-00072
    disa_stig:
      macos_26:
        - APPL-26-000051
      macos_15:
        - APPL-15-000051
      macos_14:
        - APPL-14-000051
    cmmc:
      - AC.L2-3.1.11
      - SC.L2-3.13.9
platforms:
  macOS:
    '27.0': {}
    '26.0':
      benchmarks:
        - name: disa_stig
          severity: medium
    '15.0':
      benchmarks:
        - name: disa_stig
          severity: medium
    enforcement_info:
      check:
        shell: /usr/sbin/sshd -G | /usr/bin/awk '/clientaliveinterval/{print $2}'
        result:
          integer: $ODV
      fix:
        shell: |-
          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 'clientaliveinterval $ODV' "${include_dir}01-mscp-sshd.conf" 2>/dev/null || echo "clientaliveinterval $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
odv:
  hint:
    datatype: number
    description: Number of seconds, e.g. 900
    validation:
      min: 1
  recommended: 900
  disa_stig: 900
tags:
  - 800-53r5_moderate
  - 800-53r5_high
  - 800-171
  - cnssi-1253_low
  - cnssi-1253_high
  - cmmc_lvl2
  - cnssi-1253_moderate
ddm_info:
  declarationtype: com.apple.configuration.services.configuration-files
  service: com.apple.sshd
  config_file: sshd_config
  configuration_key: ClientAliveInterval
  configuration_value: $ODV
