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
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
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.
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.
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