Local OS Version:
    版本 Windows 10 家庭中文版
    安装日期 ‎2020-‎06-‎16
    操作系统版本 19041.508
    体验 Windows Feature Experience Pack 120.2212.31.0

    Remote OS Version:
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description: Ubuntu 18.04.4 LTS
    Release: 18.04
    Codename: bionic
    Linux oasis 4.15.0-106-generic #107-Ubuntu SMP Thu Jun 4 11:27:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
    Linux version 4.15.0-106-generic (buildd@lcy01-amd64-016) (gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)) #107-Ubuntu SMP Thu Jun 4 11:27:52 UTC 2020

    VSCode Version:
    版本: 1.50.0升级为1.50.1 (user setup)
    提交: d2e414d9e4239a252d1ab117bd7067f125afd80a
    日期: 2020-10-13T15:06:15.712Z
    Electron: 9.2.1
    Chrome: 83.0.4103.122
    Node.js: 12.14.1
    V8: 8.3.110.13-electron.0
    OS: Windows_NT x64 10.0.19041

    插件remote-ssh版本
    v0.55.0

    vscode远程设置
    配置文件: C:\Users\XXW.ssh\vastai_id_rsa\config
    内容:

    1. Host 111
    2. HostName 192.168.6.240
    3. IdentityFile C:\Users\XXW\.ssh\vastai_id_rsa
    4. User kevinx
    5. Port 22
    6. IdentitiesOnly yes
    7. Host 222
    8. IdentityFile C:\Users\XXW\.ssh\vastai_id_rsa
    9. HostName 192.168.50.114
    10. User xxw
    11. Port 22
    12. IdentitiesOnly yes

    问题描述:
    通过vscode,远程连接222,一切正常。
    通过vscode,远程连接111,多次尝试连接,最后连接失败。如下:

    image.png
    有时候提示这样的

    1. [10:58:10.251] Received install output: d5db649fd3c2##24##
    2. [10:58:10.251] Server installation process already in progress - waiting and retrying
    3. [10:58:10.545] "install" terminal command done
    4. [10:58:10.546] Install terminal quit with output:
    5. [10:58:11.268] Using SSH config file "C:\Users\XXW\.ssh\config"
    6. [10:58:11.269] Running script with connection command: ssh -T -D 56593 -F "C:\Users\XXW\.ssh\config" 111 bash
    7. [10:58:11.272] Terminal shell path: C:\WINDOWS\System32\cmd.exe
    8. [10:58:13.396] "install" terminal received data: "[2J[m[Hd5db649fd3c2: running
    9. ]0;C:\WINDOWS\System32\cmd.exe[?25h"
    10. [10:58:13.397] Got some output, clearing connection timeout
    11. [10:58:13.711] "install" terminal command done
    12. [10:58:13.712] Install terminal quit with output: ]0;C:\WINDOWS\System32\cmd.exe
    13. [10:58:13.712] Received install output: ]0;C:\WINDOWS\System32\cmd.exe
    14. [10:58:13.713] Stopped parsing output early. Remaining text: ]0;C:\WINDOWS\System32\cmd.exe
    15. [10:58:13.713] Failed to parse remote port from server output
    16. [10:58:13.721] Resolver error: Error:
    17. at Function.Create (c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:1:130564)
    18. at Object.t.handleInstallOutput (c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:1:127671)
    19. at I (c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:106775)
    20. at processTicksAndRejections (internal/process/task_queues.js:94:5)
    21. at async c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:104774
    22. at async Object.t.withShowDetailsEvent (c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:109845)
    23. at async Object.t.resolve (c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:107960)
    24. at async c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:141955
    25. [10:58:13.725] TELEMETRY: {"eventName":"resolver","properties":{"outcome":"failure","reason":"UnparsableOutput","askedPw":"0","askedPassphrase":"0","asked2fa":"0","askedHostKey":"0","gotUnrecognizedPrompt":"0","remoteInConfigFile":"1"},"measures":{"resolveAttempts":1,"retries":4}}
    26. [10:58:13.728] ------

    或者这样的提示:

    1. [08:59:34.313] > Found running server...
    2. [08:59:34.320] >
    3. > *
    4. > * Reminder: You may only use this software with Visual Studio family products,
    5. > * as described in the license (https://go.microsoft.com/fwlink/?linkid=2077057)
    6. > *
    7. >
    8. > Checking server status on port 35179 with wget
    9. > failed: Connection refused.
    10. > 47b9d415b0c4##28##
    11. [08:59:34.320] Received install output: 47b9d415b0c4##28##
    12. [08:59:34.320] Server status check failed - waiting and retrying
    13. [08:59:34.623] "install" terminal command done
    14. [08:59:34.624] Install terminal quit with output:
    15. [08:59:35.334] Resolver error: Error:
    16. at Function.Create (c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:1:130564)
    17. at c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:105225
    18. at async Object.t.withShowDetailsEvent (c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:109845)
    19. at async Object.t.resolve (c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:107960)
    20. at async c:\Users\XXW\.vscode\extensions\ms-vscode-remote.remote-ssh-0.55.0\out\extension.js:127:141955
    21. [08:59:35.339] ------

    备注:
    1 用别的终端(例如cmd, MobaXterm),可以正常访问111
    2 用vscode 可以正常访问其它的服务器222.

    尝试解决方法:
    1 将本地的ssh pub秘钥中的内容替换远程服务器的.ssh目录下的authorized_keys,重启。结果还是无法连接。
    无效

    2 将本地文件 known_hosts 的内容清空
    参考 https://blog.csdn.net/weixin_42902669/article/details/106334059
    无效

    3 修改设置:”remote.SSH.useLocalServer”: false,
    参考 https://segmentfault.com/q/1010000022940805
    无效

    4 安装其它版本的vscode,
    无效

    5 安装其它版本remote-ssh插件
    无效

    6
    通过前面的观察和总结,可以得出问题一定出现在111服务器端的vscode-server

    • 用别的终端(例如cmd, MobaXterm),可以正常访问111服务器。-> 表示该服务器的ssh server没有问题
    • 用vscode 可以正常访问其它的服务器222. -> 表示本地安装的vscode没有问题
    • 那么,只有一种可能,即111服务器上的vscode-server有问题。

    删除远程服务器上的 .vscode-server文件夹 : “rm -fr ~/.vscode-server
    然后启动vscode, 重新连接111服务器,111服务器会自动下载和安装vscode server,连接成功!!!

    后续:
    经过测试发现,vscode版本从1.50.0更新到1.50.1之后,如果在不同的客户端通过vscode用同一个账户访问同一台远程服务器(例如本例中的111),就会出现上面的问题。
    解决办法:不用删除整个.vscode-server文件夹,只需要删除该文件夹下面的所有的日志文件即可(.log)。不过,比较麻烦的是,每次切换不同的客户端来访问111时,都需要实现删除.vscode-server文件夹下的log文件。**

    通过log文件发现,对于不同的客户端,server监听的端口号都不一样:
    例如pc1访问后的server上的log是:

    1. *
    2. * Visual Studio Code Server
    3. *
    4. * Reminder: You may only use this software with Visual Studio family products,
    5. * as described in the license https://aka.ms/vscode-remote/license
    6. *
    7. IP Address: 192.168.6.240
    8. Extension host agent listening on 41483
    9. [23:51:13] Extension host agent started.
    10. [23:51:17] [127.0.0.1][19238420][ManagementConnection] New connection established.
    11. [23:51:17] [127.0.0.1][a3a87239][ExtensionHostConnection] New connection established.
    12. bash: cannot set terminal process group (-1): Inappropriate ioctl for device
    13. bash: no job control in this shell
    14. [23:51:18] [127.0.0.1][a3a87239][ExtensionHostConnection] <46890> Launched Extension Host Process.
    15. [23:52:26] [127.0.0.1][19238420][ManagementConnection] The client has disconnected gracefully, so the connection will be disposed.
    16. [23:52:27] [127.0.0.1][a3a87239][ExtensionHostConnection] <46890> Extension Host Process exited with code: 0, signal: null.
    17. Last EH closed, waiting before shutting down
    18. [23:52:27] Last EH closed, waiting before shutting down
    19. Last EH closed, shutting down
    20. [23:57:27] Last EH closed, shutting down

    而pc2访问后的server上的log是:

    1. *
    2. * Visual Studio Code Server
    3. *
    4. * Reminder: You may only use this software with Visual Studio family products,
    5. * as described in the license https://aka.ms/vscode-remote/license
    6. *
    7. IP Address: 192.168.6.240
    8. Extension host agent listening on 34651
    9. [08:47:54] Extension host agent started.
    10. [08:47:58] [127.0.0.1][22513247][ManagementConnection] New connection established.
    11. [08:47:58] [127.0.0.1][8560fc28][ExtensionHostConnection] New connection established.
    12. bash: cannot set terminal process group (-1): Inappropriate ioctl for device
    13. bash: no job control in this shell
    14. [08:47:59] [127.0.0.1][8560fc28][ExtensionHostConnection] <33882> Launched Extension Host Process.
    15. [08:48:03] Installing extension: cschlosser.doxdocgen
    16. [08:48:04] Downloaded extension: cschlosser.doxdocgen undefined
    17. [08:48:05] Extracted extension to /home/VASTAI/kevinx/.vscode-server/extensions/.cschlosser.doxdocgen-1.1.0: cschlosser.doxdocgen
    18. [08:48:05] Renamed to /home/VASTAI/kevinx/.vscode-server/extensions/cschlosser.doxdocgen-1.1.0
    19. [08:48:05] Installation completed. cschlosser.doxdocgen
    20. [08:48:05] Extensions installed successfully: cschlosser.doxdocgen
    21. [08:48:51] [127.0.0.1][22513247][ManagementConnection] The client has disconnected gracefully, so the connection will be disposed.
    22. [08:48:52] [127.0.0.1][8560fc28][ExtensionHostConnection] <33882> Extension Host Process exited with code: 0, signal: null.
    23. Last EH closed, waiting before shutting down
    24. [08:48:52] Last EH closed, waiting before shutting down

    pc1对应的是41483, pc2对应的34651(只要中间没有切换client,就会保持不变)。如果pc1正常访问后退出,pc2再访问,log中所对应的端口号不一致,所以会导致连接错误。这时,删除log文件,重新连接,就会重新生成新的log,端口号就是当前pc2的端口号(当然也是重新生成的),当然就正常连接了。