# yaml-language-server: $schema=../../../../schema/control.schema.json id: CB-UBU-AUTH-020 title: Close idle shell sessions automatically finding: title: Idle shell sessions stay open forever description: A forgotten terminal, often with a root shell, can be used by anyone who reaches it. status: active profiles: [core] risk: severity: low assessment: automated tags: [accounts, session, timeout] description: | When the read-only `TMOUT` variable is set, bash and dash close an interactive shell that waited that many seconds for input. Setting it in `/etc/profile.d/` applies it to the login shells of every user, and `readonly` stops users from removing it. rationale: | Open terminals left on a console, in a jump host session or in a forgotten SSH connection are an easy way to reuse someone's access, sometimes with root privileges. impact: | Idle interactive shells exit after {{ tmout }} seconds. Long-running commands are not affected, but a shell waiting at the prompt is closed: use `tmux` or `screen` for sessions that must stay open. setting: location: /etc/profile.d/60-cirsec-tmout.sh default_value: Not set recommended_value: "TMOUT={{ tmout }}, readonly" parameters: - name: tmout type: integer description: Idle time before an interactive shell exits. unit: seconds default: 900 profile_defaults: server-hardened: 600 desktop-hardened: 600 minimum: 60 maximum: 3600 audit: manual: | Run `su -s /bin/sh -l nobody -c 'echo $TMOUT'`. It must print a value between 1 and {{ tmout }}. checks: - id: login-shell engine: shell description: TMOUT in a login shell. spec: script: | t=$(su -s /bin/sh -l nobody -c 'printf %s "${TMOUT:-}"' 2>/dev/null) || exit 3 echo "TMOUT=${t:-unset}" [ -n "$t" ] && [ "$t" -ge 1 ] && [ "$t" -le "$CB_TMOUT" ] remediation: manual: | Create `/etc/profile.d/60-cirsec-tmout.sh`: ``` TMOUT={{ tmout }} readonly TMOUT export TMOUT ``` effects: restart: session disruption: low lockout_risk: false rollback: | Delete `/etc/profile.d/60-cirsec-tmout.sh`. scripts: - id: profile engine: shell content: | f=/etc/profile.d/60-cirsec-tmout.sh cb_backup "$f" printf '%s\n' '# Written by CIRSEC Baselines CB-UBU-AUTH-020' "TMOUT=$CB_TMOUT" 'readonly TMOUT' 'export TMOUT' >"$f" chmod 644 "$f" references: - title: bash(1), Ubuntu manual pages (TMOUT) url: https://manpages.ubuntu.com/manpages/noble/man1/bash.1.html publisher: Canonical kind: vendor-doc accessed: 2026-10-19 - title: ANSSI-BP-028 v2.0 - Recommandations de configuration d'un système GNU/Linux (R32) url: https://messervices.cyber.gouv.fr/documents-guides/fr_np_linux_configuration-v2.0.pdf publisher: ANSSI kind: guide accessed: 2026-10-19 mappings: - framework: anssi-linux framework_version: "2.0" id: R32 relation: equivalent - framework: nist-800-53r5 framework_version: "5.1.1" id: AC-12 relation: equivalent - framework: cis-ubuntu-2004 framework_version: "3.0.0" id: "5.4.3.2" relation: equivalent - framework: cis-ubuntu-2204 framework_version: "3.0.0" id: "5.4.3.2" relation: equivalent - framework: cis-ubuntu-2404 framework_version: "2.0.0" id: "5.4.3.2" relation: equivalent - framework: cis-ubuntu-2604 framework_version: "1.0.0" id: "5.4.3.2" relation: equivalent threats: - framework: mitre-attack id: T1078 authors: - name: Alice github: Sn0wAlice verified: - date: 2026-10-19 by: Sn0wAlice versions: ["20.04"] environment: Proxmox VM, Ubuntu 20.04 cloud image, kernel 5.4.0-216-generic notes: "Fails on a fresh install; TMOUT 900 in core, 600 in server-hardened; kept after reboot." - date: 2026-10-19 by: Sn0wAlice versions: ["22.04"] environment: Proxmox VM, Ubuntu 22.04 cloud image, kernel 5.15.0-198-generic notes: "Fails on a fresh install; TMOUT 900 in core, 600 in server-hardened; kept after reboot." - date: 2026-10-19 by: Sn0wAlice versions: ["24.04"] environment: Proxmox VM, Ubuntu 24.04 cloud image, kernel 6.8.0-147-generic notes: "Fails on a fresh install; TMOUT 900 in core, 600 in server-hardened; kept after reboot." - date: 2026-10-19 by: Sn0wAlice versions: ["26.04"] environment: Proxmox VM, Ubuntu 26.04 cloud image, kernel 7.0.0-38-generic notes: "Fails on a fresh install; TMOUT 900 in core, 600 in server-hardened; kept after reboot." introduced_in: 0.1.0 created: 2026-10-19 updated: 2026-10-19