#!/bin/bash
# 对比当前机器（26002）与 tenda（26000）的配置差异

echo "=== 对比分析：为何 26000 能连，26002 不能 ==="
echo ""

echo "【当前机器信息】"
echo "主机名: $(hostname)"
echo "用户: $(whoami)"
echo "OpenSSH Server 版本:"
ssh -V 2>&1
echo ""

echo "步骤 1/5: 查看 sshd_config 关键配置"
echo "----------------------------------------"
cat /c/ProgramData/ssh/sshd_config | grep -E "^[^#]" | grep -E "(PubkeyAuthentication|AuthorizedKeysFile|PasswordAuthentication|PermitRootLogin|StrictModes|Match)"
echo ""

echo "步骤 2/5: 查看 authorized_keys 文件状态"
echo "----------------------------------------"
echo "文件路径: C:\\Users\\houzi\\.ssh\\authorized_keys"
ls -lh /c/Users/houzi/.ssh/authorized_keys
echo ""
echo "文件内容（前3行）:"
head -3 /c/Users/houzi/.ssh/authorized_keys
echo ""
echo "行数: $(wc -l < /c/Users/houzi/.ssh/authorized_keys)"
echo ""
echo "文件编码检测:"
file /c/Users/houzi/.ssh/authorized_keys
echo ""

echo "步骤 3/5: 检查文件权限详情"
echo "----------------------------------------"
icacls.exe "C:\\Users\\houzi\\.ssh\\authorized_keys"
echo ""

echo "步骤 4/5: 检查是否有继承权限"
echo "----------------------------------------"
icacls.exe "C:\\Users\\houzi\\.ssh\\authorized_keys" | findstr /i "inherited"
echo ""

echo "步骤 5/5: 查看最近的认证失败日志"
echo "----------------------------------------"
powershell.exe -Command "Get-WinEvent -LogName 'OpenSSH/Operational' -MaxEvents 10 | Where-Object {$_.Message -like '*failed*' -or $_.Message -like '*public*key*'} | Select-Object TimeCreated, Message | Format-List"
echo ""

echo "=== 关键问题 ==="
echo "1. tenda（26000）使用什么用户启动隧道？"
echo "2. tenda 的 authorized_keys 在哪个路径？"
echo "3. tenda 的文件权限是什么？"
echo ""
echo "请对比 tenda 机器的配置找出差异"
