简体   繁体   中英

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

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? eg the equivalent of like an iLo interface for physical machines?

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

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.

Even simpler with the latest Azure...what a lifesaver:

Azure Portal > Your VM > Run command > RunShellScript

In the textbox for Linux Shell Script, type:

ufw disable

ufw status

Click Run button. Done.

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

Method Provided by @Vince somehow did not work for me

even further simple solution

Setup your serial console Pic for serial console path

  1. first setup Username and password by going to support& trobleshott -> reset password
  2. open serial console -> log in
  3. sudo ufw disable [bamm...]

Run this on the machine as root:

ufw allow ssh

A more strict approach would be:

ufw limit ssh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM