#!/bin/bash
# 诊断 SSH Server 配置问题

echo "=== 诊断 SSH Server 配置 ==="
echo ""

echo "步骤 1/5: 查看 sshd_config 有效配置"
echo "----------------------------------------"
cat /c/ProgramData/ssh/sshd_config | grep -v "^#" | grep -v "^$"
echo ""

echo "步骤 2/5: 检查是否有 ListenAddress 限制"
echo "----------------------------------------"
cat /c/ProgramData/ssh/sshd_config | grep -i "ListenAddress"
echo ""

echo "步骤 3/5: 检查是否有 Match 规则"
echo "----------------------------------------"
cat /c/ProgramData/ssh/sshd_config | grep -A 5 "^Match"
echo ""

echo "步骤 4/5: 测试本地连接（应该成功）"
echo "----------------------------------------"
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=3 houzi@localhost "echo 'Local connection OK'" 2>&1
echo ""

echo "步骤 5/5: 查看最近的SSH日志"
echo "----------------------------------------"
powershell.exe -Command "Get-WinEvent -LogName 'OpenSSH/Operational' -MaxEvents 5 | Format-List TimeCreated, Message"
echo ""

echo "完成诊断"
