amazon-ec2 - 如果我使用 ufw 关闭端口 22,如何连接到 ec2?
问题描述
我无法连接到我在 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
--//
在此处查看我的答案 在禁用 ec2 服务器后启用防火墙端口 22
推荐阅读
- javascript - 如何在一个区间内循环这两个不透明度函数?
- android - 如何在 Gitlab CI 中检索 Android SHA-1
- javascript - 在 React 项目的 WebStorm 中使用 Flow 时如何修复这个红色下划线?
- css - 如何解决 IE 中的背景图像 css 问题
- android - Android:如何仅为我的应用设置密码/PIN?
- python - 这段代码的多处理解释是什么?
- java - 尝试使用 parseInt() 和 trim() 时出现 NumberFormatException 无法修复它
- docker - Podman(码头工人)容器
- django - “包”对象没有属性“评论”
- intellij-idea - 在 IntelliJ 中创建 Web 项目时未显示设置中的目录