You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows10下SSH连接GitHub及VM主机失败求助

Windows 10下SSH连接全面失败问题的排查与解决建议

问题背景

  • 已通过以下命令生成ed25519密钥对并添加至GitHub账户:
    ssh-keygen -t ed25519 -C myEmail@github.com
    
  • 执行SSH代理配置与连接测试命令:
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/myKey
    ssh -vvvT git@github.com
    
    返回错误:
    OpenSSH_8.8p1, OpenSSL 1.1.1l  24 Aug 2021
    debug1: Reading configuration data /c/Users/adam/.ssh/config
    debug1: /c/Users/adam/.ssh/config line 8: Applying options for github.com
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/c/Users/adam/.ssh/known_hosts'
    debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/c/Users/adam/.ssh/known_hosts2'
    debug2: resolving "github.com" port 22
    debug3: resolve_host: lookup github.com:22
    debug3: ssh_connect_direct: entering
    debug1: Connecting to github.com [20.205.243.166] port 22.
    debug3: set_sock_tos: set socket 4 IP_TOS 0x48
    debug1: connect to address 20.205.243.166 port 22: Permission denied.
    ssh: connect to host github.com port 22: Permission denied.
    
  • 当前~/.ssh/config配置:
    Host 192.168.57.10
      HostName 192.168.57.10
      User root
    # Github
    Host github.com
    User git
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/myKey
    
  • 异常现象:重启笔记本后,GitHub及本地VM(192.168.57.10)的SSH连接均失败;VSCode连接VM时返回管道错误:
    ssh: connect to host 192.168.57.10 port 22: Permission denied
    > 过程试图写入的管道不存在。
    [13:41:53.040] "install" terminal command done
    [13:41:53.041] Install terminal quit with output: 过程试图写入的管道不存在。
    [13:41:53.041] Received install output: 过程试图写入的管道不存在。
    [13:41:53.041] Failed to parse remote port from server output
    [13:41:53.041] Resolver error: Error: 
        at f.Create (c:\Users\adam\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:586041)
        at t.handleInstallOutput (c:\Users\adam\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:584693)
        at t.tryInstall (c:\Users\adam\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:681846)
        at async c:\Users\adam\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:644486
        at async t.withShowDetailsEvent (c:\Users\adam\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:647831)
        at async t.resolve (c:\Users\adam\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:645565)
        at async c:\Users\adam\.vscode\extensions\ms-vscode-remote.remote-ssh-0.76.1\out\extension.js:1:722872
    [13:41:53.044] ------
    
  • 已尝试操作:重新生成密钥、重启SSH服务,无效。

排查与解决步骤

1. 排查防火墙/安全软件拦截

  • 打开Windows Defender防火墙→「允许应用通过防火墙」,找到Git Bash或OpenSSH客户端,确保勾选「私有网络」权限
  • 暂时关闭第三方杀毒软件、防火墙工具,测试SSH连接是否恢复,排除拦截问题

2. 修复OpenSSH Authentication Agent服务配置

  • 按下Win+R输入services.msc打开服务管理器
  • 找到「OpenSSH Authentication Agent」,确认服务状态为正在运行,启动类型设为「自动」
  • 右键服务→「属性」→「登录」选项卡,选择「本地系统账户」,勾选「允许服务与桌面交互」
  • 重启服务后,在Git Bash中重新执行:
    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/myKey
    

3. 修正.ssh目录与密钥文件权限(Windows下核心要求)

Windows下SSH对文件权限严格,权限过宽会被拒绝:

  • 右键C:\Users\adam\.ssh文件夹→「属性」→「安全」→「高级」
  • 点击「禁用继承」,选择「将继承的权限转换为此对象的显式权限」
  • 删除所有非当前用户(adam)的权限条目,仅保留当前用户的「完全控制」权限
  • 对myKey文件单独设置:右键→「属性」→「安全」→「编辑」,删除除当前用户外的所有权限,仅保留当前用户的「读取」权限

4. 测试端口连通性与网络适配

  • 使用telnet测试端口是否可达:
    telnet github.com 22
    telnet 192.168.57.10 22
    
    若telnet失败:
    • 登录VM控制台,检查sshd服务是否正常运行(执行systemctl status sshd)
    • 尝试修改GitHub的SSH连接端口为443(部分网络会拦截22端口),更新~/.ssh/config:
      Host github.com
        User git
        HostName github.com
        Port 443
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/myKey
      
      重新执行ssh -vvvT git@github.com测试

5. 修复VSCode Remote-SSH配置

  • 打开VSCode→「设置」,搜索「Remote.SSH: Path」,确认路径指向Git Bash的ssh.exe(例如C:\Program Files\Git\usr\bin\ssh.exe)
  • 按F1,输入「Remote-SSH: Kill VS Code Server on Host」,选择对应的VM主机,清除缓存后重新尝试连接

内容的提问来源于stack exchange,提问作者young adam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 22:47:56