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

VS Code Remote SSH无法识别Git Bash格式的IdentityFile路径

VS Code远程SSH连接需重复输入密码的解决方法

问题描述

已在Git Bash中配置好SSH密钥并可正常使用,但通过VS Code远程资源管理器连接服务器时,每次都要求输入密码。连接时提示Setting up SSH Host mywebsite.com: (details) Initializing VS Code Server,查看详情显示no such identity: /c/Users/Adam/.ssh/id_rsa_root_mywebsite.com: No such file or directory,但该密钥文件实际存在。已将VS Code默认终端设置为Git Bash,但问题仍存在。

当前相关配置:

  • VS Code的settings.json:
    "terminal.integrated.defaultProfile.windows": "Git Bash"
    
  • SSH配置文件C:\Users\Adam\.ssh\config:
    Host mywebsite.com
      HostName mywebsite.com
      User root
      IdentityFile /c/Users/Adam/.ssh/id_rsa_root_mywebsite.com
    

解决方法

方法一:修改SSH配置文件的路径格式

VS Code远程SSH扩展默认使用Windows原生OpenSSH客户端,无法识别Git Bash的POSIX格式路径(/c/...)。将IdentityFile改为Windows兼容的路径格式即可:

修改后的C:\Users\Adam\.ssh\config:

Host mywebsite.com
  HostName mywebsite.com
  User root
  IdentityFile C:\Users\Adam\.ssh\id_rsa_root_mywebsite.com

或者使用正斜杠的Windows路径:

IdentityFile /C/Users/Adam/.ssh/id_rsa_root_mywebsite.com

(注意盘符C需大写)

方法二:让VS Code使用Git Bash的SSH客户端

如果希望继续使用Git Bash的路径格式,可配置VS Code调用Git Bash中的SSH程序:

在VS Code的settings.json中添加以下配置:

"remote.SSH.path": "C:\\Program Files\\Git\\usr\\bin\\ssh.exe"

(路径需根据你的Git实际安装位置调整,比如C:/Program Files/Git/usr/bin/ssh.exe也是合法格式)

配置完成后重启VS Code,再尝试远程连接即可。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 00:22:03