macOS 15 - Sequoia

The macOS system must configure the SSH ServerAliveInterval to 900

STIG ID: APPL-15-000110 | SRG: SRG-OS-000163-GPOS-00072 | Severity: Medium | CCI: CCI-001133 | Vulnerability ID: V-268444

Description

SSH must be configured with an Active Server Alive Maximum Count set to 900.Setting the Active Server Alive Maximum Count to 900 will log users out after a 900-second interval of inactivity.Note: /etc/ssh/ssh_config will be automatically modified to its original state following any update or major upgrade to the operating system.

Check

C-268444r1034800_chk

Verify the macOS system is configured to set the SSH ServerAliveInterval to 900 with the following command:ret="pass"for u in $(/usr/bin/dscl . -list /Users UniqueID | /usr/bin/awk '$2 > 500 {print $1}'); dossh=$(/usr/bin/sudo -u $u /usr/bin/ssh -G . | /usr/bin/grep -c "^serveraliveinterval 900")if [[ "$ssh" == "0" ]]; thenret="fail"breakfidone/bin/echo $retIf the result is not "pass", this is a finding.

Fix

F-72375r1034799_fix

Configure the macOS system to set the SSH ServerAliveInterval to 900 with the following command:include_dir=$(/usr/bin/awk '/^Include/ {print $2}' /etc/ssh/ssh_config | /usr/bin/tr -d '*')ssh_config_string=("ServerAliveInterval 900")for ssh_config in $ssh_config_string; dossh_setting=$(echo $ssh_config | /usr/bin/cut -d " " -f1)/usr/bin/grep -qEi "^$ssh_setting" "${include_dir}01-mscp-ssh.conf" && /usr/bin/sed -i "" "s/^$ssh_setting.*/${ssh_config}/" "${include_dir}01-mscp-ssh.conf" || echo "$ssh_config" >> "${include_dir}01-mscp-ssh.conf"for u in $(/usr/bin/dscl . list /users shell | /usr/bin/egrep -v '(^_)|(root)|(/usr/bin/false)' | /usr/bin/awk '{print $1}'); doconfig=$(/usr/bin/sudo -u $u /usr/bin/ssh -Gv . 2>&1)configfiles=$(echo "$config" | /usr/bin/awk '/Reading configuration data/ {print $NF}'| /usr/bin/tr -d '\r')configarray=( ${(f)configfiles} )if ! echo $config | /usr/bin/grep -q -i "$ssh_config" ; thenfor c in $configarray; doif [[ "$c" == "/etc/ssh/crypto.conf" ]]; thencontinuefi/usr/bin/sudo -u $u /usr/bin/grep -qEi "^$ssh_setting" "$c" && /usr/bin/sed -i "" "s/^$ssh_setting.*/${ssh_config}/I" "$c"if [[ "$c" =~ ".ssh/config" ]]; thenif /usr/bin/grep -qEi "$ssh_setting" "$c" 2> /dev/null; thenold_file=$(cat ~$u/.ssh/config)echo "$ssh_config" > ~$u/.ssh/configecho "$old_file" >> ~$u/.ssh/configfifidonefidonedone