Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enabled UFW, now can't connect to my ubuntu azure vm

Tags:

azure

ufw

I turned on UFW on my ubuntu linux vm in azure, and now I can't connect to it over ssh (or anything). On both the private and public IP.

Is there any way for me to connect to my vm now? e.g. the equivalent of like an iLo interface for physical machines?

like image 282
danielpops Avatar asked Aug 07 '16 22:08

danielpops


People also ask

Can you use Azure portal on Ubuntu?

Azure virtual machines (VMs) can be created through the Azure portal. The Azure portal is a browser-based user interface to create Azure resources. This quickstart shows you how to use the Azure portal to deploy a Linux virtual machine (VM) running Ubuntu 18.04 LTS.

Does UFW allow default SSH?

By default, when enabled UFW will block external access to all ports on a server. In practice, that means if you are connected to a server via SSH and enable ufw before allowing access via the SSH port, you'll be disconnected.


3 Answers

Here is an msdn blog describing exactly this situation.

In a nutshell:

  1. Logon to the Azure portal
  2. VM Name > Extensions > Add > Select “Custom Script for Linux” > Create
  3. Upload the bash script I've appended below. Call it ufw_disable.sh
  4. Set the command as sh ufw_disable.sh
  5. Click OK, and wait for the script to deploy and execute.

The script will be run as root, so there is no need to do sudo inside the script (in fact this will cause things to fail).

ufw_disable.sh:

ufw disable
ufw status
like image 52
Vince Avatar answered Sep 28 '22 22:09

Vince


You can add your new IP from the cloud shell.

az vm run-command invoke -g VMResourceGroup -n VM --command-id RunShellScript --scripts "ufw allow from 74.125.90.78 to anyport 22"

Change the ip address and the port to your own values.

like image 43
ra213 Avatar answered Sep 28 '22 21:09

ra213


Azure portal provides the easiest way to get into the serial console through its portal. Follow these steps

Azure Portal > Your VM > Support + Troubleshooting > Serial Console.

Now even if you firewall is blocking ssh, you can access this serial console and simply disable it using sudo ufw disable or add the 22 ssh port to the firewall

like image 41
Hariharnath Paduchuru Avatar answered Sep 28 '22 22:09

Hariharnath Paduchuru