# Ensure sshd PermitUserEnvironment is disabled

The 'PermitUserEnvironment' setting controls whether the '~/.ssh/environment' and 'environment=' options in '~/.ssh/authorized_keys' are processed by sshd. Allowing users to set their own environment variables can introduce a significant security risk. A malicious user could set dangerous variables, such as LD_PRELOAD, to execute arbitrary code, bypass security controls, or escalate privileges. Disabling this feature is a critical hardening step to reduce the attack surface of the SSH service. The audit script verifies the current effective setting by querying the SSH daemon directly. The remediation script ensures this configuration is explicitly set to 'no' in the 'sshd_config' file and reloads the service. The recommended state for all security levels (Basic, Moderate, and Strict) is 'no' because this is a binary security control with no valid use case for being enabled in a hardened environment. The risk it introduces far outweighs any potential convenience.

## Recommended State Configuration

| Security Level | Value |
|----------------|-------|
| **Basic** | `['no']` |
| **Moderate** | `['no']` |
| **Strict** | `['no']` |
| **Type** | `ENUM` |

## Audit Script Working

Bash script that queries the effective SSH server configuration for 'PermitUserEnvironment' using the 'sshd -T' command. The script must parse the output and return only the value (e.g., 'no'), without any additional text or labels.

## Remediation Script Working

Bash script that accepts one positional argument representing the desired state (e.g., 'no'). The script must modify the '/etc/ssh/sshd_config' file to set 'PermitUserEnvironment' to this value, adding the line if it does not exist or uncommenting and updating it if it does. After modification, the script must restart the sshd service to apply the change. The script must return 'true' on successful completion and 'false' on failure.

