Windows → Windows VSCode Remote SSH 不同子网下的配置流程
·
Windows → Windows VSCode Remote SSH 不同子网下的配置流程
适用于:
- 本地:Windows 11
- 远程:Windows 10/11
- 通过 Tailscale / 内网 IP 连接
- 使用 VSCode Remote‑SSH
✅ 一、远程机器(Win10)准备
0️⃣ 安装 tailscale 并登录
自行官网下载并登录,随后即可知道每台设备的ip (100.xxx.xx.xx)
1️⃣ 安装 OpenSSH Server
以管理员身份打开 PowerShell:
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
启动服务:
Start-Service sshd
Set-Service -Name sshd -StartupType Automatic
确认状态:
Get-Service sshd
应该看到:
Status : Running
2️⃣ 创建开发用户(不要用 Administrator,这里创建的开发用户名是’dev’)
net user dev 密码 /add
3️⃣ 将 dev 加入管理员组(关键步骤 ✅)
⚠ 这是 VSCode Remote‑SSH 在 Windows 上正常运行的关键。
Add-LocalGroupMember -Group "Administrators" -Member "dev"
验证:
Get-LocalGroupMember Administrators
确保列表中包含:
dev
4️⃣ 重启 sshd 服务(无需重启电脑)
Restart-Service sshd
5️⃣ (推荐/可选)设置默认 Shell 为 CMD
PowerShell 在 VSCode Remote‑SSH 下偶尔有兼容问题。
建议改为 CMD:
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" `
-Name DefaultShell `
-Value "C:\Windows\System32\cmd.exe" `
-PropertyType String -Force
然后:
Restart-Service sshd
✅ 二、本地机器(Win11)配置
0️⃣ 安装 tailscale 并登录
自行官网下载并登录,随后即可知道每台设备的ip (100.xxx.xx.xx)
1️⃣ 安装 VSCode 插件
安装:
Remote - SSH
2️⃣ 修改 VSCode settings.json
打开:
Ctrl + Shift + P
Preferences: Open Settings (JSON)
加入:
{
"remote.SSH.remotePlatform": {
"100.69.54.92": "windows"
},
"remote.SSH.useExecServer": false
}
⚠ 必须明确指定 windows,否则可能误判为 linux。
3️⃣ 以管理员身份运行 VSCode(第一次推荐)
右键 VSCode:
以管理员身份运行
(第一次成功后可恢复普通启动)
✅ 三、连接流程
1️⃣ 测试 SSH 是否正常
在本地 PowerShell:
ssh dev@100.xx.xx.xx
能登录说明 OK。
2️⃣ 使用 VSCode 连接
Remote-SSH: Connect to Host
选择:
dev@100.xx.xx.xx
第一次会自动安装:
C:\Users\dev\.vscode-server
✅ 四、常见错误与解决方案
❌ 错误:no sshd parent proc
原因:
Get-CimInstance Win32_Process 权限不足
解决:
✅ 将 dev 加入 Administrators 组
✅ Restart-Service sshd
✅ 重新连接
❌ 错误:Failed to parse remote port
原因:
VSCode 误判远程平台为 Linux
解决:
"remote.SSH.remotePlatform": {
"IP地址": "windows"
}
❌ PowerShell 权限错误
解决:
✅ 改默认 Shell 为 CMD
✅ 或管理员身份运行 VSCode 一次
✅ 五、安全最佳实践(推荐)
🔐 不要直接用 Administrator 登录
推荐结构:
| 用户 | 用途 |
|---|---|
| Administrator | 系统维护 |
| dev | 开发 SSH 连接 |
🔐 (可选)启用 SSH Key(后续优化)
禁用密码登录:
编辑:
C:\ProgramData\ssh\sshd_config
修改:
PasswordAuthentication no
PubkeyAuthentication yes
然后:
Restart-Service sshd
🔐 限制 22 端口来源(如果用 Tailscale)
建议只允许:
100.x.x.x 网段
✅ 六、最终架构
Win11 (VSCode)
↓ SSH
Tailscale / 内网 IP
↓
Win10 (OpenSSH Server)
↓
C:\Users\dev\.vscode-server
✅ 七、完整成功标志
当成功时:
远程会出现目录:
C:\Users\dev\.vscode-server
VSCode 状态栏显示:
SSH: 100.xx.xx.xx
且不再出现:
no sshd parent proc
这就是 Windows → Windows VSCode Remote‑SSH 的稳定 pipeline。
更多推荐


所有评论(0)