#!/bin/bash
# 修改 MaxAuthTries 限制

SSHD_CONFIG="/c/ProgramData/ssh/sshd_config"

echo "=== 修改 MaxAuthTries 限制 ==="
echo ""

echo "步骤 1/3: 检查当前配置"
grep -i "MaxAuthTries" "$SSHD_CONFIG" || echo "未设置 MaxAuthTries"
echo ""

echo "步骤 2/3: 设置 MaxAuthTries=20"
# 删除已有的配置
sed -i '/^#*MaxAuthTries/d' "$SSHD_CONFIG"
# 添加新配置
echo "MaxAuthTries 20" >> "$SSHD_CONFIG"
echo "✓ MaxAuthTries 已设置为 20"
echo ""

echo "步骤 3/3: 重启 SSH Server（隧道会断开）"
net.exe stop sshd
sleep 2
net.exe start sshd
echo "✓ SSH Server 已重启"
echo ""

echo "=== 修复完成 ==="
echo ""
echo "请重新启动隧道："
echo "ssh -N -o ServerAliveInterval=30 -R 26002:localhost:22 root@82.29.54.80 > ~/Desktop/tunnel-26002.log 2>&1 &"
