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
Server Fault is a question and answer site for system and network administrators. It only takes a minute to sign up.Sign up to join this community
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.
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
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
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