id: os_sshd_channel_timeout_configure
title: Configure SSHD Channel Timeout to $ODV
discussion: |
  If SSHD is enabled it _MUST_ be configured with session ChannelTime out set to $ODV.

  This will set the time out when the session is inactive.

  NOTE: /etc/ssh/sshd_config will be automatically modified to its original state following any update or major upgrade to the operating system.

  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 '/channeltimeout/{print $2}'
result:
  string: $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 'channeltimeout $ODV' "${include_dir}01-mscp-sshd.conf" 2>/dev/null || echo "channeltimeout $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-95307-5
  cci:
    - CCI-001133
    - CCI-002361
  800-53r5:
    - SC-10
    - AC-12
  800-53r4:
    - SC-10
  srg:
    - SRG-OS-000163-GPOS-00072
    - SRG-OS-000279-GPOS-00109
  disa_stig:
    - APPL-26-000120
  800-171r3:
    - 03.01.11
    - 03.13.09
  cmmc:
    - AC.L2-3.1.11
    - SC.L2-3.13.9
odv:
  hint: Channel type and number of seconds.
  recommended: session:*=900
  stig: session:*=900
macOS:
  - '26.0'
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: ChannelTimeout
  configuration_value: $ODV