Fail to SSH connect to Ubuntu vm using Visual Studio Code

Jinghui Niu 21 Reputation points
2022-07-24T19:06:06.7+00:00

I have a Ubuntu vm on Azure. I'm using Visual Studio Code running on Debian. I can successfully SSH connect from my Debian terminal. However, with the same command line connecting to VM using Visual Studio Code, it gave me Permission denied (publickey) error:

> [11:33:35.157] Log Level: 2 > [11:33:35.182] remote-ssh@0.84.0 > [11:33:35.201] linux x64 > [11:33:35.260] SSH Resolver called for "ssh-remote+7b22686f73744e616d65223a2232302e32352e3135362e313838222c2275736572223a22737368206a696e676875695f61745f636169706f227d", attempt 1 > [11:33:35.303] "remote.SSH.useLocalServer": true > [11:33:35.305] "remote.SSH.path": undefined > [11:33:35.305] "remote.SSH.configFile": undefined > [11:33:35.305] "remote.SSH.useFlock": true > [11:33:35.305] "remote.SSH.lockfilesInTmp": false > [11:33:35.306] "remote.SSH.localServerDownload": auto > [11:33:35.306] "remote.SSH.remoteServerListenOnSocket": false > [11:33:35.306] "remote.SSH.showLoginTerminal": false > [11:33:35.307] "remote.SSH.defaultExtensions": [] > [11:33:35.307] "remote.SSH.loglevel": 2 > [11:33:35.307] "remote.SSH.enableDynamicForwarding": true > [11:33:35.307] "remote.SSH.enableRemoteCommand": false > [11:33:35.308] "remote.SSH.serverPickPortsFromRange": {} > [11:33:35.308] "remote.SSH.serverInstallPath": {} > [11:33:35.363] SSH Resolver called for host: ssh @ > [11:33:35.363] Setting up SSH remote "" > [11:33:35.388] Acquiring local install lock: /tmp/vscode-remote-ssh-66bf00c8-install.lock > [11:33:35.396] Looking for existing server data file at /home//.config/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-66bf00c8-3b889b090b5ad5793f524b5d1d39fda662b96a2a-0.84.0/data.json > [11:33:35.408] Using commit id "3b889b090b5ad5793f524b5d1d39fda662b96a2a" and quality "stable" for server > [11:33:35.423] Install and start server if needed > [11:33:35.436] PATH: /usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games > [11:33:35.446] Checking ssh with "ssh -V" > [11:33:35.617] > OpenSSH_8.4p1 Debian-5+deb11u1, OpenSSL 1.1.1n 15 Mar 2022 > > [11:33:35.645] askpass server listening on /run/user/1000/vscode-ssh-askpass-f30e9f85fa23a0172b857a9abc9da3dc3e97a727.sock > [11:33:35.646] Spawning local server with {"serverId":1,"ipcHandlePath":"/run/user/1000/vscode-ssh-askpass-8c03855ae692e0dd483e445bb5bc6ca5dc08d0c3.sock","sshCommand":"ssh","sshArgs":["-v","-T","-D","37803","-o","ConnectTimeout=60","ssh @"],"serverDataFolderName":".vscode-server","dataFilePath":"/home//.config/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-66bf00c8-3b889b090b5ad5793f524b5d1d39fda662b96a2a-0.84.0/data.json"} > [11:33:35.646] Local server env: {"SHELL":"/bin/bash","DISPLAY":":0","ELECTRON_RUN_AS_NODE":"1","SSH_ASKPASS":"/home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/local-server/askpass.sh","VSCODE_SSH_ASKPASS_NODE":"/usr/share/code/code","VSCODE_SSH_ASKPASS_EXTRA_ARGS":"--ms-enable-electron-run-as-node","VSCODE_SSH_ASKPASS_MAIN":"/home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/askpass-main.js","VSCODE_SSH_ASKPASS_HANDLE":"/run/user/1000/vscode-ssh-askpass-f30e9f85fa23a0172b857a9abc9da3dc3e97a727.sock"} > [11:33:35.686] Spawned 721 > [11:33:36.215] Server delay-shutdown request failed: connect ENOENT /run/user/1000/vscode-ssh-askpass-8c03855ae692e0dd483e445bb5bc6ca5dc08d0c3.sock > [11:33:36.252] > local-server-1> Spawned ssh, pid=731 > [11:33:36.273] stderr> OpenSSH_8.4p1 Debian-5+deb11u1, OpenSSL 1.1.1n 15 Mar 2022 > [11:33:36.640] stderr> debug1: Server host key: ecdsa-sha2-nistp256 SHA256:91fCxAoajFxaMXdy2N8G5KgFKt4/JLbHwhglIlFrQyg > [11:33:36.856] stderr> ssh @: Permission denied (publickey). > [11:33:36.879] > local-server-1> ssh child died, shutting down > [11:33:36.880] Local server exit: 0 > [11:33:36.881] Received install output: local-server-1> Spawned ssh, pid=731 > OpenSSH_8.4p1 Debian-5+deb11u1, OpenSSL 1.1.1n 15 Mar 2022 > debug1: Server host key: ecdsa-sha2-nistp256 SHA256:91fCxAoajFxaMXdy2N8G5KgFKt4/JLbHwhglIlFrQyg > ssh @: Permission denied (publickey). > local-server-1> ssh child died, shutting down > > [11:33:36.910] Resolver error: Error: Permission denied (publickey). > at Function.Create (/home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/extension.js:1:585222) > at /home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/extension.js:1:583279 > at Object.t.handleInstallOutput (/home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/extension.js:1:583796) > at Object.e [as tryInstallWithLocalServer] (/home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/extension.js:1:624373) > at processTicksAndRejections (node:internal/process/task_queues:96:5) > at async /home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/extension.js:1:643506 > at async Object.t.withShowDetailsEvent (/home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/extension.js:1:647224) > at async /home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/extension.js:1:622845 > at async T (/home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/extension.js:1:619351) > at async Object.t.resolveWithLocalServer (/home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/extension.js:1:622460) > at async Object.t.resolve (/home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/extension.js:1:644834) > at async /home//.vscode/extensions/ms-vscode-remote.remote-ssh-0.84.0/out/extension.js:1:727082 > [11:33:36.933] ------

I'm really confused why it SSH works in terminal but not in VSC, with exactly the same command line?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,332 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jackson Martins 10,571 Reputation points MVP
    2022-07-24T19:31:22.443+00:00

    Hi @Jinghui Niu
    I had the same problem and I did these steps to fix

    • Exit completely out of VSCode so that no VSCode processes are running. Force quit if you have to.
    • ssh to the remote machine(s) and delete the ~/.vscode-server directory with rm -Rf ~/.vscode-server/
    • If you get any “cannot remove [file]: Device or resource busy” errors then look for stuck processes:
    • lsof | grep $HOME/.vscode-server | awk '{ print $2 }' | sort -u
    • … then kill those processes, then trying removing the directory again.
    • Restart VSCode.

    Reference: https://earlruby.org/2021/06/fixing-vscode-when-it-keeps-dropping-ssh-connections/

    Get in touch if you need more help with this issue.

    --please don't forget to "[Accept the answer]" if the reply is helpful--
    Best regards

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.