Locked myself out of SSH with UFW in EC2 AWS

后端 未结 6 901
孤城傲影
孤城傲影 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条回答
  •  独厮守ぢ
    2020-12-04 15:03

    I know this is an old question but I fixed mine by adding a command in View/Change User Data using bootcmd

    I first stopped my instance

    Then I added this in User Data

    #cloud-config
    bootcmd:
     - cloud-init-per always fix_broken_ufw_1 sh -xc "/usr/sbin/service ufw stop >> /var/tmp/svc_$INSTANCE_ID 2>&1 || true" 
     - cloud-init-per always fix_broken_ufw_2 sh -xc "/usr/sbin/ufw disable>> /var/tmp/ufw_$INSTANCE_ID 2>&1 || true"
    

    #Note: My instance is Ubuntu

提交回复
热议问题