AWS EC2, ufw enable 후 ssh 접속 불가 문제

이성원·2024년 3월 27일
0

문제 상황

Ubuntu는 기본 방화벽으로 ufw를 사용한다. 이 때, ufw를 disable 했다가 enable 했을 때, ssh 접속이 다시 되지 않는 경우가 있다.

해결 방법

  1. 인스턴스를 정지 후 인스턴스 설정으로 이동해서 "사용자 데이타 편집"에 ufw disable 시키는 코드를 추가한다.

아래 코드로 바꿔 넣으면 된다.

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
--//

해당 코드는 아래 링크를 참조하면 된다.
https://medium.com/@manprajapat/cant-access-ssh-after-enable-ufw-in-ec2-aws-koffee-with-kode-5e481a5631c6

  1. 인스턴스 다시 시작

  2. SSH 접속 가능해짐.

profile
개발자

0개의 댓글

관련 채용 정보