如果我使用 ufw 关闭端口 22,我如何连接到 ec2?

How can i connect to ec2 if i close port 22 using ufw?

我无法连接到我在 ec2 上的实例。 之前一切正常,我想现在是ufw的问题。

当我配置我的服务器时,我为 80 端口启用了 ufw,也许它禁用了 22 端口。 因为之前一切正常,现在ssh连不上了

如何连接到我的 ec2 实例并再次允许 22 端口?

你要检查EC2实例下的安全组和enable/add那边的22端口。 之后就可以在80端口查看apache了。

如果您不小心阻塞了端口,那么我们 link 可以再次重置它 https://u.osu.edu/walujo.1/2017/04/21/how-to-fix-ec2-instance-when-you-accidentally-block-port-22/

您可以使用以下最简单的方法(用户数据)关闭 ufw,然后访问该实例并编辑您的防火墙。

  1. 停止实例
  2. 编辑用户数据以禁用 ufw 一次并允许您访问实例
  3. 启动实例

用户数据如下:

Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0

--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"

#cloud-config
cloud_final_modules:
- [scripts-user, once]

--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"

#!/bin/bash
sudo ufw disable
--//

在这里查看我的回答enable firewall port 22 on ec2 server after disable it