目录
连接远程服务器
过程试图写入的管道不存在
一般在配置好Remote-SSH插件后,经过以下步骤就能连上远程服务器。
但有时候会报“过程试图写入的管道不存在”错如下:
[22:45:47.063] Log Level: 2
[22:45:47.074] SSH Resolver called for "work-01", attempt 1
[22:45:47.074] "remote.SSH.useLocalServer": false
[22:45:47.075] "remote.SSH.useExecServer": false
[22:45:47.075] "remote.SSH.showLoginTerminal": true
[22:45:47.075] "remote.SSH.remotePlatform":
[22:45:47.076] "remote.SSH.path": C:\Program Files\Git\usr\bin\ssh.exe
[22:45:47.076] "remote.SSH.configFile": undefined
[22:45:47.076] "remote.SSH.useFlock": true
[22:45:47.076] "remote.SSH.lockfilesInTmp": false
[22:45:47.076] "remote.SSH.localServerDownload": auto
[22:45:47.076] "remote.SSH.remoteServerListenOnSocket": false
[22:45:47.078] "remote.SSH.showLoginTerminal": true
[22:45:47.078] "remote.SSH.defaultExtensions": []
[22:45:47.078] "remote.SSH.loglevel": 2
[22:45:47.078] "remote.SSH.enableDynamicForwarding": true
[22:45:47.078] "remote.SSH.enableRemoteCommand": false
[22:45:47.078] "remote.SSH.serverPickPortsFromRange": {}
[22:45:47.078] "remote.SSH.serverInstallPath": {}
[22:45:47.082] VS Code version: 1.82.0
[22:45:47.082] Remote-SSH version: remote-ssh@0.106.5
[22:45:47.082] win32 x64
[22:45:47.084] SSH Resolver called for host: work-01
[22:45:47.084] Setting up SSH remote "work-01"
[22:45:47.087] Using commit id "e7e037083ff4455cf320e344325dacb480062c3c" and quality "stable" for server
[22:45:47.089] Install and start server if needed
[22:45:48.514] Checking ssh with "C:\Program Files\Git\usr\bin\ssh.exe -V"
[22:45:48.575] > OpenSSH_9.0p1, OpenSSL 1.1.1q 5 Jul 2022[22:45:48.581] Running script with connection command: "C:\Program Files\Git\usr\bin\ssh.exe" -T -D 60261 "work-01" bash
[22:45:48.583] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[22:45:49.166] > The authenticity of host can't be established.
> ED25519 key fingerprint is SHA256:txGFNbtmUFQ6mpsyeuR2fmzBg4fEOPyTURsf00012IU.
> This key is not known by any other names
> Are you sure you want to continue connecting (yes/no/[fingerprint])?]0;C:\WINDOWS\System32\cmd.exe
[22:45:49.167] Got some output, clearing connection timeout
[22:45:49.176] > The authenticity of host can't be established.
> ED25519 key fingerprint is SHA256:txGFNbtmUFQ6mpsyeuR2fmzBg4fEOPyTURsf00012IU.
> This key is not known by any other names
> Are you sure you want to continue connecting (yes/no/[fingerprint])? Host key verification failed.
> 过程试图写入的管道不存在。
从前往后分析日志信息可以看到两处
[22:45:47.076] "remote.SSH.configFile": undefined
[22:45:47.087] Using commit id "e7e037083ff4455cf320e344325dacb480062c3c" and quality "stable" for server
[22:45:47.089] Install and start server if needed
第一处容易修复
第二处的意思是远程服务器上的vscode版本不兼容,需要安装 commit id 指定的版本,需要手动安装。从这个网址下载对应的安装包,注意将<commit id>替换成报错信息提示的版本 https://update.code.visualstudio.com/commit:<commit id>/server-linux-x64/stable
wget https://update.code.visualstudio.com/commit:e7e037083ff4455cf320e344325dacb480062c3c/server-linux-x64/stable
如果服务器上下载很慢就在本地下载好了传上去。在服务器上将安装包解压到 ~/.vscode-server/bin/<commit id> 目录中,如果没有该目录就自己建。
多数时候到这一步问题就能解决了,如果不能,还可尝试把这几处取消掉
通过跳板机/堡垒机连接服务器
配置C:\Users\user\.ssh\config文件,在里面先定义好jumpserver,再通过ProxyCommand指定ssh接连命令,如下。然后Connect to Host...连接workstation即可。
Host jumpserver
HostName <跳板机IP>
Port <跳板机端口>
User <跳板机用户名>
Host workstation
HostName <工作站IP>
Port <工作站端口>
User <工作站用户名>
ProxyCommand ssh -W %h:%p jumpserver
进入远程服务器上的docker容器
按图1~7步安装扩展插件,其中docker插件安装好后vscode左侧会出现数字5所示docker图标。Remote Development插件一定要安装,不然会找不到数字11所示Attach Visual Studio Code选项。插件安装好后点数字8处docker图标可以显示出该服务器上的所有Containers,可以选择目标容器进入(8~11步)。最后可以看到vscode已经登录进容器中了,可以打开自己的代码进行调试了(12~13步)。
代码编辑
找不到头文件
进行C/C++编程时,如果没把自定义头文件路径写到配置文件里,编辑区域会用红色波浪线标识未定义的符号,并提示"cannot open source file"或"Include file not found in browse.path.C/C++"。但有时候明明已经将头文件目录添加到"includePath"中了,vscode还是找不到头文件。
这有可能是配置了"configurationProvider"。如下图所示,指定了cmake-tools进行头文件提示,但vscode环境并没有安装cmake-tools,所以它总是找不到头文件。 解决办法:
1、直接删除"configurationProvider"那一行;
2、安装上"CMake Tools"插件。
代码自动格式化不生效
正常情况安装了Black Formatter插件后就可以对代码自动格式化使代码变得整洁易读。
但有时无论怎么设置这个功能都不生效,特别是它之前一直工作得好好的,突然哪天就失效了。有可能是你手欠点了Update,导致和你的vscode版本不兼容。