본문 바로가기

경험

[AWS] Port 22 : Operation timed out

잘 실행되던 ec2 인스턴스가 갑자기 ssh 접속되지 않았다.

인스턴스를 중지했다가 다시 시작했지만 그럼에도 접속되지 않았다.

 

오류 문구를 확인하니 Port 22 : Operation timed out 이라 적혀있어 이 오류에 대해 찾아봤다.

인바운드 규칙도 잘 설정되어 있고 mac의 원격로그인 또한 모두로 설정되어 있어 원인을 찾는데 어려움이 있었다.

검색 중 한 블로그에서 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, 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
--//

위 명령어 입력

 

인스턴스 재시작 후

sudo ufw allow 22

 

인스턴스 다시 중지 -> 사용자 데이터 편집

명령어를 지운 후 다시 실행하면 완료