Locked myself out of SSH with UFW in EC2 AWS

后端 未结 6 907
孤城傲影
孤城傲影 2020-12-04 14:38

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

sudo ufw allow 27017

When th

6条回答
  •  Happy的楠姐
    2020-12-04 15:21

    I have the same problem and found out that this steps works:

    1- Stop your instance

    2- Go to `Instance Settings -> View/Change user Data

    3- Paste this

    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, always]
    --//
    Content-Type: text/x-shellscript; charset="us-ascii"
    MIME-Version: 1.0
    Content-Transfer-Encoding: 7bit
    Content-Disposition: attachment; filename="userdata.txt"
    #!/bin/bash
    ufw disable
    iptables -L
    iptables -F
    --//
    

    4- Start your instance

    Hope it works for you

提交回复
热议问题