我无法连接到 ec2 上的实例。
一切都很好,我认为现在 ufw 有问题。

当我配置我的服务器时,我为 80 端口启用了 ufw,也许它禁用了 22 端口。
因为早期一切正常,但现在我无法通过 ssh 连接。

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

最佳答案

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

  • 停止实例
  • 编辑用户数据,禁用ufw一次,让你访问实例
  • 启动实例

  • 以下是用户数据:
    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

    关于amazon-ec2 - 如果我使用 ufw 关闭端口 22,我如何连接到 ec2?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52544733/

    10-14 17:22
    查看更多