728x90

특정 IP만 SSH 접속 허용하기특정 IP만 SSH 접속할 수 있도록 제한하기

목차

1 방법: hosts.allow, hosts.deny 설정[편집]

 리눅스 로그인 성공한 아이피 목록 보기 문서를 참고하십시오.

[root@zetawiki ~]# cat /var/log/secure* | grep Accepted | awk '{print $9"\t"$11"\t"$14}' | sort | uniq root 113.157.124.168 ssh2 root 135.79.246.217 ssh2 root 135.79.246.54 ssh2 root 135.79.246.80 ssh2

→ 113.157.124.168와 135.79.246.XXX 대역에서 로그인 성공한 기록이 있다...

# # hosts.allow This file describes the names of the hosts which are # allowed to use the local INET services, as decided # by the '/usr/sbin/tcpd' server. # sshd: 113.157.124.168, 135.79.246.

→ 113.157.124.168와 135.79.246.XXX 대역을 허용

위와 같이 한줄에 적어도 되지만, 아이피가 많아지면 관리가 어렵다. 아래와 같이 여러줄로 나누어 적어도 된다.

sshd: 113.157.124.168 sshd: 135.79.246.

# # hosts.deny This file describes the names of the hosts which are # *not* allowed to use the local INET services, as decided # by the '/usr/sbin/tcpd' server. # # The portmap line is redundant, but it is left to remind you that # the new secure portmap uses hosts.deny and hosts.allow. In particular # you should know that NFS uses portmap! sshd: ALL

→ 나머지는 모두 ssh 접근 불가

sshd를 재시작해야 적용된다.

[root@zetawiki ~]# service sshd restart Stopping sshd: [ OK ] Starting sshd: [ OK ]

2 테스트[편집]

허용되지 않은 IP에서 접속시도시 아래와 같이 접속 실패

[root@zetawiki ~]# ssh root@example.com ssh_exchange_identification: Connection closed by remote host

3 같이 보기[편집]

4 참고[편집]

728x90

'프로그래밍 > 리눅스' 카테고리의 다른 글

도커 개념 정리  (0) 2022.05.24
리눅스 파일명으로 검색  (0) 2020.03.12
GREP 활용  (0) 2019.04.24
리눅스 파티션 관리  (0) 2016.01.14
apache server 버전 확인  (0) 2015.09.14

+ Recent posts