WEBTOOLIST.
STATIC WEB PLATFORM
NO ACCOUNTS / NOTHING TO INSTALL

$ webtoolist --script ssh-hardening-audit

SSH Hardening Audit

Inspect sshd configuration for common risky settings without changing anything.

category Security shell Bash 4+ updated 2026-09-09
sshsecurityaudithardening
Safety notes
  • Read-only audit; it does not edit sshd_config.
  • Test any configuration change in a second session before closing your current one.
commands involved: ssh

Dependencies: sshd, grep

Usage

  • Run as root (or with read access to /etc/ssh/sshd_config).
  • Review each FAIL line against your threat model; some environments need password auth.

Script

#!/usr/bin/env bash
set -euo pipefail

config="${SSHD_CONFIG:-/etc/ssh/sshd_config}"
[[ -r "$config" ]] || { echo "cannot read $config" >&2; exit 1; }

check() {
  local key="$1" want="$2" line
  line="$(grep -Ei "^[[:space:]]*${key}[[:space:]]+" "$config" | tail -n1 || true)"
  if [[ -z "$line" ]]; then
    echo "WARN  $key not set explicitly (defaults apply)"
    return
  fi
  local value="${line#*[[:space:]]}"
  if [[ "$value" == "$want" ]]; then
    echo "OK    $key $value"
  else
    echo "FAIL  $key $value (want $want)"
  fi
}

check PermitRootLogin no
check PasswordAuthentication no
check PermitEmptyPasswords no
check X11Forwarding no
check MaxAuthTries 3
check ClientAliveInterval 300

echo
echo "== effective configuration =="
sshd -T 2>/dev/null | grep -Ei 'permitrootlogin|passwordauthentication|maxauthtries|allowusers|port ' || true

Example

sudo ./ssh-hardening-audit
SSHD_CONFIG=/etc/ssh/sshd_config.d/10-hardening.conf ./ssh-hardening-audit

Notes

  • sshd -T shows the merged effective config, including Include files.
  • Disabling password auth without a working key first can lock you out — verify key login in a separate session.

Related scripts

File Permission Audit

Find world-writable files and directories, excluding known-safe locations.

Security

Batch Command Runner

Run one command on a list of SSH hosts, sequentially, with clear output.

Automation

PATH Audit

Check PATH for missing, duplicate, or world-writable directories.

Linux Utilities