I have ubuntu VM running in azure.

By mistake, I enable ubuntu firewall using this command

sudo ufw enable

and I forgot to enable SSH port(22) in ubuntu firewall

Now I am not able to get access my VM using SSH.

What to do now


You could use Linux Custom Script Extension to disable Ubuntu firewall on your VM.

Firstly, you need write a script name as script.sh. Add following line to your script.

ufw disable

Notes: Don't need add sudo on your script.

Also, you could open port 22 on firewall, just modify your script like below:

ufw allow 22

On Azure Portal, find Custom Script Extension. Your resource group-->your VM-->Extensions-->Add-->Custom Script For Linux enter image description here

After the extension is installed successful, you could ssh to your VM.


You could uninstall the extension on Azure Portal and execute the following script again.

ufw disable
ufw status

Please ensure firewall is inactive. You could check log on Portal. enter image description here

Also, you could use telnet to check whether port 22 is listening.

telnet IP 22

When the firewall is disabled, but you could not ssh to your VM, you had better check your Azure NSG, please ensure port 22 is added to inbound rules.

  • I had the same issue and this helped me "unlock" the instance . Thanks! – Sagi Iltus Dec 28 '17 at 14:57

The easier way is to headover to Azure Portal > Your VM > Support + Troubleshooting > Serial Console. It comes with Windows and Linux VMs and simply disable it there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.