在EC2 AWS中使用UFW将自己锁定在SSH之外 [英] Locked myself out of SSH with UFW in EC2 AWS

查看:93
本文介绍了在EC2 AWS中使用UFW将自己锁定在SSH之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu上有一个EC2实例。
我使用了 sudo ufw enable ,只允许了mongodb端口

I have an EC2 Instance with Ubuntu. I used sudo ufw enable and after only allow the mongodb port

sudo ufw allow 27017

ssh连接断开时,我无法重新连接

When the ssh connection broke, I can´t reconnect

推荐答案

以某种方式 Mahesh 答案对我不起作用,如果您碰巧正穿上鞋子,请尝试此操作。

Somehow Mahesh's answer didn't work for me, if you happen to be in my shoes, try this.


  • 启动一个新实例(恢复实例) 。

  • 停止原始实例(请勿终止)

  • 从原始实例中分离卷(问题卷)

  • 将其作为/ dev / sdf附加到恢复实例。

  • 通过ssh / putty登录恢复实例

  • 运行 sudo lsblk 以显示附件卷并确认问题卷的名称。通常以 / dev / xvdf 开头。我的是 / dev / xvdf1

  • 安装问题量。

  • Launch a new instance (recovery instance).
  • Stop the original instance (DO NOT TERMINATE)
  • Detach the volume (problem volume) from the original instance
  • Attached it to the recovery instance as /dev/sdf.
  • Login to the recovery instance via ssh/putty
  • Run sudo lsblk to display attached volumes and confirm the name of the problem volume. It usually begins with /dev/xvdf. Mine is /dev/xvdf1
  • Mount problem volume.

$ sudo mount /dev/xvdf1 /mnt
$ cd /mnt/etc/ufw


  • 打开 ufw 配置文件

    $ sudo vim ufw.conf
    


  • 按i编辑文件。

  • ENABLED = yes 更改为 ENABLED = no

  • 键入Ctrl-C并输入:wq保存文件。

  • 使用以下命令显示ufw conf文件的内容,并确保 ENABLED =是已更改为 ENABLED = no

  • Press i to edit the file.
  • Change ENABLED=yes to ENABLED=no
  • Type Ctrl-C and type :wq to save the file.
  • Display content of ufw conf file using the command below and ensure that ENABLED=yes has been changed to ENABLED=no

    $ sudo cat ufw.conf 
    


  • 卸载量

  • Unmount volume

    $ cd ~
    $ sudo umount /mnt
    


  • 从恢复实例中分离问题卷,并将其作为/ dev / sda1重新附加到原始实例。

  • Detach problem volume from recovery instance and re-attach it to the original instance as /dev/sda1.

    来源:此处

    这篇关于在EC2 AWS中使用UFW将自己锁定在SSH之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆