connection lost when I connected to vs code

Pravin kumar 20 Reputation points
2025-01-04T11:14:36.8333333+00:00

I am able to connect my VM in command prompt. when I try to connect Host in VS Code it successfully connecting but after 10-20 sec connection lost and trying to reconnect for a while. Then I am unable to connect via CMD also. after I restart the machine, it works normally in CMD but when I try to connect to VS Code the same problem occurs.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
{count} votes

Accepted answer
  1. Mounika Reddy Anumandla 6,310 Reputation points Microsoft External Staff Moderator
    2025-01-06T04:42:17.86+00:00

    Hi Pravin kumar,

    Thank you for your patience while we are reviewing your query!

    This issue appears to be related to your VS Code Remote SSH extension and how it interacts with your VM's SSH server.

    The below tutorial walks you through creating and connecting to a virtual machine (VM) on Azure using the Visual Studio Code Remote - SSH extension. https://code.visualstudio.com/docs/remote/ssh-tutorial

    Can you please confirm if you have followed the steps mentioned. And also, the below article covers troubleshooting tips and tricks for each of the Visual Studio Code Remote Development extensions. See the SSH, Containers, and WSL articles for details on setting up and working with each specific extension.

    https://code.visualstudio.com/docs/remote/troubleshooting#_troubleshooting-hanging-or-failing-connections

    Also, if the issue still persists, please provide me with the snapshot of the error message you are getting or confirm if the Symptoms include repeatedly seeing the dialog Disconnected. Attempting to reconnect.... Please feel free to tag me in the comments.

    Hope this helps!If the comment is helpful, please "upvote" or tag me in the comments.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. hossein jalilian 10,825 Reputation points Volunteer Moderator
    2025-01-04T19:22:15.04+00:00

    Thanks for posting your question in the Microsoft Q&A forum.

    The issue you're experiencing with VS Code losing connection to your VM is a common problem. Here are some steps to resolve it:

    1. Increase the connection timeout: Set remote.SSH.connectTimeout to 60 in VS Code settings
    2. Clear the VS Code server cache on the remote machine:
    • Exit VS Code completely
    • SSH into the remote VM
      • Delete the .vscode-server directory: rm -Rf ~/.vscode-server/
    1. Kill the VS Code server on the host:
    • Open the command palette (Ctrl+Shift+P or Cmd+Shift+P on Mac)
      • Run "Remote-SSH: Kill VS Code Server on Host"
    1. Check for and kill any stuck processes: lsof | grep $HOME/.vscode-server | awk '{ print $2 }' | sort -u Then terminate those processes
    2. Disable local server download: Set "remote.SSH.useLocalServer": false in VS Code settings
    3. Verify the SSH configuration:
    • Ensure the correct port (usually 22) is specified in your .ssh/config file
      • Check that the full path to your identity file is correct
    1. If using Azure, check the VM's networking rules: Ensure NRMS-Rule-106 is not blocking the connection

    If the problem persists, try connecting with the remote.SSH.showLoginTerminal setting enabled to see if VS Code is waiting for any prompts


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful

    0 comments No comments

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.