Cannot SSH to Azure VM

29k Views Asked by At

I have a Ubuntu VM on Azure (Resource Group, not the Classic VM) and it all worked out of the box. I recently tried to SSH into the VM using Putty and I could not.

I get the error: Network Error: Connection Timed out.

I have made sure that the port 22 is opened for SSH on the VM Inbound rules.

SSH Port 22 Allowed

I had this VM setup about 2 months ago for a side project and at that time I was able to SSH easily without any troubles. Now I can't. Am I missing something?

PS: The HTTP works fine. I have the website running on it and it shows up in the browser. Also, I tried using a browser-based SSH client and it was able to SSH into the VM.

5

There are 5 best solutions below

3
On BEST ANSWER

Looks to be an issue with the local firewall. Try resetting the SSH configuration in the portal.

  1. Go to Azure Portal
  2. Select VM in question
  3. Select Reset Password
  4. Select Reset Configuration Only
  5. Select Update

Screenshot of the process here!

0
On

Create below directory : mkdir -p /run/sshd

Then restart service : systemctl restart ssh

This will definitely solve your issue.

2
On

When a new VM is created on Azure, by-default the Protocol TCP on Port 22 is Disabled. Need to allow this.

Follow: https://medium.com/techinpieces/practical-azure-how-to-enable-ssh-on-azure-vm-84d8fba8103e

0
On

I am adding this because it might help someone, the chosen answer did not work for me

for some reason the firewall on the ubuntu server

Go to Serial Console type in your ssh username and you will be logged into the server

Check the firewall status to see if port 22 is allowed

sudo ufw status verbose

If the rule is not there then add it

sudo ufw allow ssh

enter image description here

0
On

I encountered the same issue. The following is how I solve this issue:

  1. Don't add any port While creating your VM, do it only after only the VM is created
  2. Add the port 22 in the networking tab until the VM status is Running.