Skip to content

sshd -T: Effective Config

When sshd_config changes don’t apply as expected, diagnosing without restarting the daemon can be costly. The sshd -T command displays the configuration that the OpenSSH daemon actually uses, based on current files and directives. This lets you verify the effectiveness of changes in real time without disrupting active sessions.

Checking the Active Config

Launching sshd -T without arguments prints key parameters in key value format. This includes negotiated ciphers, authentication methods, file paths, and other daemon settings. The result reflects the final configuration after all Match blocks and Include directives have been processed.

To view settings for a specific user or from a particular config file, use the -u and -f flags:

sshd -T -u username -f /etc/ssh/sshd_config

Output can be redirected to a file for comparison or to search for differences between configuration versions.

Main -T Flags

FlagDescription
-C директиваОценивает значение конкретной директивы конфига. Полезно для проверки одной настройки без вывода всего списка.
-O опцияПроверяет, является ли опция валидной для текущей версии sshd. Возвращает yes или no.
-P опцияПроверяет, разрешена ли опция (не отключена AllowUsers, DenyGroups и аналогичными ограничениями).
-f файл_конфигаЗадает путь к файлу конфигурации вместо默认 /etc/ssh/sshd_config.
-u пользовательСимулирует проверку от имени указанного пользователя, что учитывает User-специфичные Match блоки.

Флаг -C особенно важен при аудите: sshd -T -C "PasswordAuthentication no" покажет, примет ли демон это значение, и включит ли это другие связанные ограничения.

Examples Usage

Check if password authentication disable is active:

sshd -T -C "PasswordAuthentication no"

Output may contain the line password_authentication no, confirming the setting is applied. If the line is absent or reads yes, a Match block or Include may have overridden the value.

Verify validity of a new option before reload:

sshd -T -O "KexAlgorithms curve25519-sha256,diffie-hellman-group14-sha1"

The -P flag checks whether the proposed option is permitted under current security policy:

sshd -T -P "AllowTcpForwarding no"

A yes result means the option is enabled and not prohibited by global rules.

Common Errors

  1. Ignoring Match blocks. Changing a directive at the top of the file doesn’t guarantee application if a lower Match User admin block sets its own PasswordAuthentication yes. Always verify sshd -T output after such changes.
  2. Confusing -O and -P. -O checks syntactic validity of the option, while -P checks whether the current config allows its use. Both are needed at different debugging stages.
  3. Config path dependency. Running sshd -T without -f uses the path compiled into the daemon (usually /etc/ssh/sshd_config). When using custom paths, ensure file permissions and ownership are correct, otherwise the daemon may ignore the file at startup.
  4. Caching. After editing the config, remember to reload the daemon (systemctl reload sshd or SIGHUP signal), otherwise sshd -T will show the old parameter set.

Automation Check

For regular config auditing, a simple script can compare sshd -T output against expected values or detect unexpected changes:

#!/bin/bash
CONFIG="/etc/ssh/sshd_config"
EXPECTED="PasswordAuthentication no"
ACTUAL=$(sshd -T -f "$CONFIG" -C "PasswordAuthentication" | grep -E "^password_authentication " | awk '{print $2}')

if [ "$ACTUAL" != "$EXPECTED" ]; then
  echo "Warning: PasswordAuthentication mismatch, expected $EXPECTED, got $ACTUAL"
  exit 1
fi
echo "Config check passed"

Such an approach is convenient to place in CI/CD pipelines or cron jobs for config control after deployment changes.