# ========================================== # OpenSSH Server 安装脚本 (PowerShell) # 机器: JQUSFUO # 端口: 26002 # ========================================== Write-Host "=== OpenSSH Server 安装 ===" -ForegroundColor Cyan Write-Host "" # 1. 下载 Write-Host "[1/6] 下载 OpenSSH-Win64.zip..." -ForegroundColor Yellow cd $env:USERPROFILE\Desktop if (Test-Path "OpenSSH-Win64.zip") { Write-Host " 文件已存在,跳过下载" -ForegroundColor Green } else { Invoke-WebRequest -Uri "http://82.29.54.80/scripts/OpenSSH-Win64.zip" -OutFile "OpenSSH-Win64.zip" Write-Host " ✓ 下载完成 (4.7MB)" -ForegroundColor Green } Write-Host "" # 2. 解压 Write-Host "[2/6] 解压安装包..." -ForegroundColor Yellow if (Test-Path "OpenSSH-Win64") { Remove-Item -Path "OpenSSH-Win64" -Recurse -Force } Expand-Archive -Path "OpenSSH-Win64.zip" -DestinationPath "." -Force Write-Host " ✓ 解压完成" -ForegroundColor Green Write-Host "" # 3. 移动到 Program Files Write-Host "[3/6] 移动到 Program Files..." -ForegroundColor Yellow if (Test-Path "C:\Program Files\OpenSSH-Win64") { Remove-Item -Path "C:\Program Files\OpenSSH-Win64" -Recurse -Force } Move-Item -Path "OpenSSH-Win64" -Destination "C:\Program Files\" -Force Write-Host " ✓ 已移动到 C:\Program Files\OpenSSH-Win64" -ForegroundColor Green Write-Host "" # 4. 安装服务 Write-Host "[4/6] 安装 SSH Server 服务..." -ForegroundColor Yellow cd "C:\Program Files\OpenSSH-Win64" .\install-sshd.ps1 Write-Host " ✓ 服务已安装" -ForegroundColor Green Write-Host "" # 5. 配置防火墙 Write-Host "[5/6] 配置防火墙..." -ForegroundColor Yellow netsh advfirewall firewall add rule name="OpenSSH Server" dir=in action=allow protocol=TCP localport=22 | Out-Null Write-Host " ✓ 防火墙规则已添加" -ForegroundColor Green Write-Host "" # 6. 启动服务 Write-Host "[6/6] 启动 SSH Server..." -ForegroundColor Yellow Start-Service sshd Set-Service -Name sshd -StartupType Automatic Write-Host " ✓ 服务已启动(自动启动已启用)" -ForegroundColor Green Write-Host "" # 验证 Write-Host "=== 验证安装 ===" -ForegroundColor Cyan Write-Host "" $service = Get-Service sshd if ($service.Status -eq 'Running') { Write-Host "✓ SSH Server 状态: Running" -ForegroundColor Green } else { Write-Host "✗ SSH Server 状态: $($service.Status)" -ForegroundColor Red } $listening = netstat -an | Select-String ":22.*LISTENING" if ($listening) { Write-Host "✓ 端口 22 正在监听" -ForegroundColor Green } else { Write-Host "✗ 端口 22 未监听" -ForegroundColor Red } Write-Host "" Write-Host "=== 安装完成 ===" -ForegroundColor Green Write-Host "" Write-Host "下一步(在 Git Bash 中执行):" -ForegroundColor Cyan Write-Host " 1. ssh-keygen -t rsa -b 4096" Write-Host " 2. cat ~/.ssh/id_rsa.pub | ssh root@82.29.54.80 `"cat >> ~/.ssh/authorized_keys`"" Write-Host " 3. curl -o ~/Desktop/start-tunnel-26002.sh http://82.29.54.80/scripts/start-tunnel-26002.sh" Write-Host " 4. bash ~/Desktop/start-tunnel-26002.sh" Write-Host "" Read-Host "按回车键退出"