# ========================================== # 启动 SSH Server 服务 # 需要管理员权限 # ========================================== #Requires -RunAsAdministrator Write-Host "=== 启动 SSH Server ===" -ForegroundColor Cyan Write-Host "" # 检查服务是否存在 $service = Get-Service sshd -ErrorAction SilentlyContinue if ($null -eq $service) { Write-Host "错误: SSH Server 未安装" -ForegroundColor Red Write-Host "" Write-Host "请先运行 setup-ssh.ps1 安装 OpenSSH Server" -ForegroundColor Yellow Write-Host "" Read-Host "按回车键退出" exit 1 } # 检查服务状态 if ($service.Status -eq 'Running') { Write-Host "SSH Server 已在运行中" -ForegroundColor Green Write-Host "" Write-Host "服务状态: $($service.Status)" Write-Host "启动类型: $($service.StartType)" Write-Host "" } else { Write-Host "正在启动 SSH Server..." -ForegroundColor Yellow try { Start-Service sshd -ErrorAction Stop Set-Service -Name sshd -StartupType Automatic Write-Host "✓ SSH Server 启动成功" -ForegroundColor Green Write-Host "" # 验证端口 Start-Sleep -Seconds 2 $listening = netstat -an | Select-String ":22.*LISTENING" if ($listening) { Write-Host "✓ 端口 22 正在监听" -ForegroundColor Green } else { Write-Host "! 警告: 端口 22 未监听" -ForegroundColor Yellow } } catch { Write-Host "✗ 启动失败: $_" -ForegroundColor Red Write-Host "" Write-Host "请检查服务配置或重新运行 setup-ssh.ps1" -ForegroundColor Yellow } } Write-Host "" Write-Host "现在可以运行 start-tunnel.sh 启动隧道" -ForegroundColor Cyan Write-Host "" Read-Host "按回车键退出"