VS Code Remote-SSH连接服务器失败求助:终端可连插件不行
我使用以下SSH配置连接服务器:
Host <name> HostName <IP_Address> User ubuntu IdentityFile ~/.ssh/my_ssh.txt
通过VS Code的Remote-SSH插件连接时,出现错误:
Could not establish connection to <name>
且卡在VS Code Server连接环节。但在VS Code终端中执行ssh <name>可以正常连接服务器,完整错误日志如下:
[02:05:12.309] Server installation process already in progress - waiting and retrying [02:05:13.325] Resolver error: Error: at m.Create (c:\Users\h_jal\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:584145) at c:\Users\h_jal\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:644535 at async t.withShowDetailsEvent (c:\Users\h_jal\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:647428) at async t.resolve (c:\Users\h_jal\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:645160) at async c:\Users\h_jal\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:720916 [02:05:13.339] ------
清理服务器上残留的VS Code Server进程
通过终端SSH登录服务器,执行ps aux | grep code-server找到所有相关进程,用kill -9 <进程ID>强制终止这些进程,之后重新尝试Remote-SSH连接。更新Remote-SSH插件
当前使用的插件版本是0.102.0,属于较旧版本,直接在VS Code扩展市场将Remote-SSH更新至最新版,多数旧版本的兼容性问题已被修复。检查密钥文件权限
本地的~/.ssh/my_ssh.txt密钥文件权限需设置为600(Windows系统右键文件→属性→安全,仅保留当前用户的读写权限);服务器端的~/.ssh/authorized_keys权限设为600,~/.ssh目录权限设为700,权限异常会导致插件连接失败。重置Remote-SSH插件状态
在VS Code中按下Ctrl+Shift+P打开命令面板,输入Remote-SSH: Kill VS Code Server on Host,选择对应的服务器,之后重新发起连接。手动指定VS Code Server安装路径
在VS Code设置中搜索remote.SSH.serverInstallPath,手动设置服务器上的安装目录(例如/home/ubuntu/.vscode-server),确保该目录拥有读写权限。关闭代理或VPN
若当前开启了代理或VPN,先关闭后再尝试连接,代理可能干扰插件的SSH连接通道。
内容的提问来源于stack exchange,提问作者Ham82

