use*_*525 1 ssh virtual-machines ufw azure ubuntu-16.04
我有在 azure 中运行的 ubuntu VM。
错误地,我使用此命令启用了 ubuntu 防火墙
须藤 ufw 启用
我忘了在 ubuntu 防火墙中启用 SSH 端口(22)
现在我无法使用 SSH 访问我的 VM。
现在做什么
您可以使用Linux 自定义脚本扩展来禁用 VM 上的 Ubuntu 防火墙。
首先,您需要将脚本名称写为script.sh
. 将以下行添加到您的脚本中。
ufw disable
Run Code Online (Sandbox Code Playgroud)
注意:不需要在脚本上添加 sudo。
此外,您可以在防火墙上打开端口 22,只需修改您的脚本,如下所示:
ufw allow 22
Run Code Online (Sandbox Code Playgroud)
在 Azure 门户上,找到自定义脚本扩展。 Your resource group-->your VM-->Extensions-->Add-->Custom Script For Linux
扩展安装成功后,您可以通过 ssh 连接到您的虚拟机。
更新:
您可以在 Azure 门户上卸载扩展并再次执行以下脚本。
ufw disable
ufw status
Run Code Online (Sandbox Code Playgroud)
此外,您可以使用telnet
检查端口 22 是否正在侦听。
telnet IP 22
Run Code Online (Sandbox Code Playgroud)
当防火墙被禁用,但你不能 ssh 到你的 VM 时,你最好检查你的 Azure NSG,请确保端口 22 被添加到入站规则中。