# ========================================== # Windows SSH 隧道一键安装脚本 # 使用方法:irm http://82.29.54.80/scripts/install-windows-tunnel.ps1 | iex # ========================================== #Requires -RunAsAdministrator $SERVER = "82.29.54.80" $SCRIPT_BASE = "http://82.29.54.80/scripts" $INSTALL_DIR = "$env:USERPROFILE\Desktop\ssh-tunnel" Write-Host "=== Windows SSH 隧道安装 ===" -ForegroundColor Cyan Write-Host "" # 1. 创建目录 Write-Host "[1/5] 创建安装目录..." -ForegroundColor Yellow New-Item -ItemType Directory -Path $INSTALL_DIR -Force | Out-Null Set-Location $INSTALL_DIR Write-Host " 安装位置: $INSTALL_DIR" -ForegroundColor Green Write-Host "" # 2. 下载脚本 Write-Host "[2/5] 下载脚本文件..." -ForegroundColor Yellow $files = @( "start-tunnel.sh", "start-ssh-service.ps1", "check-tunnel.sh", "stop-tunnel.sh" ) foreach ($file in $files) { try { Invoke-WebRequest -Uri "$SCRIPT_BASE/$file" -OutFile $file -UseBasicParsing Write-Host " ✓ $file" -ForegroundColor Green } catch { Write-Host " ✗ $file 下载失败" -ForegroundColor Red } } Write-Host "" # 3. 安装OpenSSH Server Write-Host "[3/5] 配置OpenSSH Server..." -ForegroundColor Yellow $sshServer = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*' if ($sshServer.State -ne 'Installed') { Write-Host " 安装中..." -ForegroundColor Yellow Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 | Out-Null Write-Host " ✓ 已安装" -ForegroundColor Green } else { Write-Host " ✓ 已安装" -ForegroundColor Green } Start-Service sshd Set-Service -Name sshd -StartupType Automatic Write-Host " ✓ SSH 服务已启动" -ForegroundColor Green Write-Host "" # 4. 配置防火墙 Write-Host "[4/5] 配置防火墙..." -ForegroundColor Yellow $rule = Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue if ($null -eq $rule) { New-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -DisplayName "OpenSSH Server (sshd)" -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 | Out-Null Write-Host " ✓ 防火墙规则已添加" -ForegroundColor Green } else { Write-Host " ✓ 防火墙规则已存在" -ForegroundColor Green } Write-Host "" # 5. 生成SSH密钥 Write-Host "[5/5] 配置SSH密钥..." -ForegroundColor Yellow $sshDir = "$env:USERPROFILE\.ssh" $privateKey = "$sshDir\id_rsa" if (!(Test-Path $sshDir)) { New-Item -ItemType Directory -Path $sshDir -Force | Out-Null } if (!(Test-Path $privateKey)) { & "C:\Windows\System32\OpenSSH\ssh-keygen.exe" -t rsa -b 4096 -f $privateKey -N '""' -C "windows-tunnel@$env:COMPUTERNAME" Write-Host " ✓ SSH密钥已生成" -ForegroundColor Green } else { Write-Host " ✓ SSH密钥已存在" -ForegroundColor Green } Write-Host "" # 完成 Write-Host "=== 安装完成 ===" -ForegroundColor Green Write-Host "" Write-Host "下一步操作:" -ForegroundColor Cyan Write-Host " 1. 打开 Git Bash" -ForegroundColor White Write-Host " 2. cd ~/Desktop/ssh-tunnel" -ForegroundColor White Write-Host " 3. 上传公钥到服务器:" -ForegroundColor White Write-Host " cat ~/.ssh/id_rsa.pub | ssh root@$SERVER 'cat >> ~/.ssh/authorized_keys'" -ForegroundColor Gray Write-Host " 4. 启动隧道:" -ForegroundColor White Write-Host " bash start-tunnel.sh" -ForegroundColor Gray Write-Host "" Write-Host "脚本位置: $INSTALL_DIR" -ForegroundColor Gray Write-Host "" Read-Host "按回车键退出"