리눅스

리눅스(Ubuntu) ssh서버에 fail2ban을 적용하여 무작위 로그인 시도 방어하기

wr-rainforest 2024. 4. 23. 15:09

 

블로그 주인이 운영중인 리눅스 서버의 로그인 실패 기록들. 많기도 많다.

 

원격 서버를 관리하기 위해서 ssh 서버를 주로 사용합니다.

하지만 외부에 공개되어 있는 만큼 공격 시도가 자주 들어오고는 합니다.

fail2ban 을 사용하여 ssh 서버에 대한 무작위 로그인 시도를 방어하는 방법에 대해 알아보겠습니다.

 

fail2ban이란?

fail2ban은 로그인 실패 로그를 지속적으로 검사하며, 특정 아이피에서 너무 많은 로그인 실패 기록이 감지될 경우 해당 IP 주소로부터의 새 연결을 거부하도록 방화벽을 설정하는 프로그램입니다.

https://github.com/fail2ban/fail2ban

 

GitHub - fail2ban/fail2ban: Daemon to ban hosts that cause multiple authentication errors

Daemon to ban hosts that cause multiple authentication errors - fail2ban/fail2ban

github.com

글 작성일 (24/04/22)기준 깃헙 스타 10.4k를 달성한 프로젝트입니다.

fail2ban 설치

sudo apt update
sudo apt install fail2ban

서비스 등록

시스템 재시작 시에도 제대로 작동할 수 있게 서비스 등록해 줍니다.

sudo systemctl enable fail2ban
sudo systemctl restart fail2ban
sudo systemctl status fail2ban

 

fail2ban 기본 설정이 완료되었습니다.

단, fail2ban은 잘못된 인증 시도를 감소시켜 줄 뿐 기본적으로 약한 인증에 대해서는 방어하지 못한다는 점을 꼭 인지하셔야 합니다.

 

깃허브 readme 발췌

Though Fail2Ban is able to reduce the rate of incorrect authentication attempts, it cannot eliminate the risk presented by weak authentication. Set up services to use only two factor, or public/private authentication mechanisms if you really want to protect services.