1

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

user416525
  • 19
  • 1
  • 2

2 Answers2

6

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.

Update:

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.

Shui shengbao
  • 3,503
  • 1
  • 10
  • 20
3

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

Frank Fu
  • 163
  • 1
  • 2
  • 7
  • Much easier than @Shui shengbao's solution (which of course also works, it's just jumping through several hoops to achieve the same effect) – András Aszódi Mar 05 '20 at 14:40