Windows 打开SSH 提供给Claude Code 作为测试机器的通道方案
1. 安装并启动 OpenSSH 服务端
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
Start-Service sshd
Set-Service -Name sshd -StartupType Automatic
2. 放行防火墙(通常自动加,保险起见)
New-NetFirewallRule -Name sshd -DisplayName ‚OpenSSH Server' -Enabled True `
-Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
3. 默认 shell 设为 PowerShell(否则默认 cmd,很多命令不好用)
New-ItemProperty -Path “HKLM:\SOFTWARE\OpenSSH” -Name DefaultShell `
-Value “C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe” -PropertyType String -Force
4. 授权我的公钥
$key = ‚ssh-ed25519 xxxxxxxxxxxxxxxxxxxxxxxxx claude-silk-debug'
第 4 步分两种情况(很关键,弄错就登不上):
-
neo 是普通用户:
-
New-Item -ItemType Directory -Force -Path C:\Users\neo.ssh | Out-Null
-
Add-Content C:\Users\neo.ssh\authorized_keys $key
-
neo 是管理员(多数情况):Windows 的 sshd 对管理员账号只认这个文件,且权限必须收紧,否则会被静默拒绝:
-
Add-Content C:\ProgramData\ssh\administrators_authorized_keys $key
-
icacls C:\ProgramData\ssh\administrators_authorized_keys /inheritance:r /grant “Administrators:F” /grant “SYSTEM:F”
弄好后跟我说一声,我这边直接连:ssh -i <私钥> [email protected]。私钥我生成在会话临时目录里(没放进仓库,也没碰你的 ~/.ssh),用完你随时在 Windows 上把那行公钥删掉即可撤销。