Issue connecting vscode to azure vm using ssh

NARENDRAN RAMASENDERAN 0 Reputation points
2025-01-13T07:22:50.15+00:00

I am trying to connect my virtual machine using my visual studio code using remote-ssh but it keeps saying "connection not established" and when I ping it in powershell it says connection reset by port 22. I have checked on serial console on the vm and there are no errors there that indicate any issues regarding ssh.

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

2 answers

Sort by: Most helpful
  1. Mahesh Goud Juvvadi 1,745 Reputation points Microsoft Vendor
    2025-01-13T09:59:19.6333333+00:00

    Hi NARENDRAN RAMASENDERAN,

    Thank you for reaching out to the Microsoft Q&A platform.

    Based on your question description we understand that you are facing an issue while connecting to azure VM using Visual Studio via SSH.

    Here are some steps you can take to troubleshoot and resolve this issue:

    Please check the VS Code Configuration with the Remote-SSH extension in VS Code connections configuration.

    Make sure you have the latest Azure SDK installed and ensure that your Visual Studio is updated to the latest version.

    If you have access to the VM through the Azure Serial Console, check the SSH service status with below command.

    sudo systemctl status sshd

    If the SSH service is not running, start it:

    sudo systemctl start sshd

    Please check the Firewall Settings on the VM that are not blocking any SSH connections.

    Please find the below similar issue articles for you reference:

    https://zcusa.951200.xyz/en-us/answers/questions/939587/fail-to-ssh-connect-to-ubuntu-vm-using-visual-stud

    https://stackoverflow.com/questions/64034813/vs-code-remote-ssh-connection-not-working

    I hope this information is helpful. Please feel free to reach out if you have any further questions.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    User's image

    Thanks.


  2. Ankush Raj 245 Reputation points Microsoft Employee
    2025-01-13T10:04:14.89+00:00

    Hi @NARENDRAN RAMASENDERAN

    Thanks for posting this query.

    To help me understand the situation better, you can confirm the following on your behalf.

    If the SSH connection was working before (as per the OS), do you recall any recent changes that might have impacted it? (could be any minor change)

    Another thing to check is whether port 22 (used for SSH) is open. You can do this using tool like Test-NetConnection or telnet.

    It’d also be helpful to double-check the Network Security Group (NSG) rules to ensure port 22 is allowed for your IP address.

    On the VM itself, could you confirm if the SSH service is running? For Linux, that’d be the sshd service, and for Windows, it’s OpenSSH.

    Are you connecting to the VM using its public IP, private IP, or a domain name? If it’s a public IP, make sure it’s static so it doesn’t change unexpectedly.

    Lastly, do try to connect the vm from different terminal other than VS code and check the status.

    I'm also attaching a relevant link. Please do check it out - https://code.visualstudio.com/docs/remote/ssh

    If the answer is helpful, please click ACCEPT ANSWER and kindly upvote it so that other people who faces similar issue may get benefitted from it.

    If you have any further questions about this answer, please click Comment.

    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.