I am running Ubuntu 22.04 LTS and I bought a VM on Azure recently. Today, when I tried to log in using SSH, I failed to log in.
The command I am using is ssh -i ~/.ssh/<KEY> user@public_IP_address
.
I am trying to use the SSH command from Ubuntu's bash terminal but also tried using PuTTy unsuccessfully earlier today.
I tried the same in my environment got the same error like below:
This error usually occurs if network security group rules for the virtual machine port 22 (SSH) is not open for inbound traffic rule.
To check this use telnet <vmpublicip> 22
it is not open connection to the host you need to update the NSG rules to allow your IP address to connect.
In virtual machine -> networking -> Add inbound port rule -> destination port add 22
like below:
Now, when I try to connect with SSH using ssh user@public_IP_address
or ssh -v -i ~/.ssh/id_rsa user@public_IP_address
it connected successfully like below.
If still error persists, check if the vm is in running status by navigating to boot diagnostics and serial log as below:
Check uncomplicated firewall status, firewall is blocking SSH connections and that rules are in active using below command:
sudo ufw status
sudo ufw allow ssh
sudo ufw enable
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)