"특정 IP만 SSH 접속 허용하기"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(사용자 4명의 중간 판 4개는 보이지 않습니다)
4번째 줄: 4번째 줄:
==방법: hosts.allow, hosts.deny 설정==
==방법: hosts.allow, hosts.deny 설정==
{{참고|리눅스 로그인 성공한 아이피 목록 보기}}
{{참고|리눅스 로그인 성공한 아이피 목록 보기}}
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# cat /var/log/secure.* | grep Accepted | awk '{print $9"\t"$11"\t"$14}' | sort | uniq
[root@zetawiki ~]# cat /var/log/secure* | grep Accepted | awk '{print $9"\t"$11"\t"$14}' | sort | uniq
root    113.157.124.168 ssh2
root    113.157.124.168 ssh2
root    135.79.246.217  ssh2
root    135.79.246.217  ssh2
root    135.79.246.54  ssh2
root    135.79.246.54  ssh2
root    135.79.246.80  ssh2
root    135.79.246.80  ssh2
</source>
</syntaxhighlight>
:→ 113.157.124.168와 135.79.246.XXX 대역에서 로그인 성공한 기록이 있다...
:→ 113.157.124.168와 135.79.246.XXX 대역에서 로그인 성공한 기록이 있다...


;[[/etc/hosts.allow]] 수정
* [[/etc/hosts.allow]] 수정
<source lang='properties'>
<syntaxhighlight lang='properties'>
#
#
# hosts.allow This file describes the names of the hosts which are
# hosts.allow This file describes the names of the hosts which are
21번째 줄: 21번째 줄:
#
#
sshd: 113.157.124.168, 135.79.246.
sshd: 113.157.124.168, 135.79.246.
</source>
</syntaxhighlight>
:→ 113.157.124.168와 135.79.246.XXX 대역을 허용
:→ 113.157.124.168와 135.79.246.XXX 대역을 허용
위와 같이 한줄에 적어도 되지만, 아이피가 많아지면 관리가 어렵다. 아래와 같이 여러줄로 나누어 적어도 된다.
위와 같이 한줄에 적어도 되지만, 아이피가 많아지면 관리가 어렵다. 아래와 같이 여러줄로 나누어 적어도 된다.
<source lang='properties'>
<syntaxhighlight lang='properties'>
sshd: 113.157.124.168
sshd: 113.157.124.168
sshd: 135.79.246.
sshd: 135.79.246.
</source>
</syntaxhighlight>


;[[/etc/hosts.deny]] 수정
* [[/etc/hosts.deny]] 수정
<source lang='properties'>
<syntaxhighlight lang='properties'>
#
#
# hosts.deny This file describes the names of the hosts which are
# hosts.deny This file describes the names of the hosts which are
40번째 줄: 40번째 줄:
# you should know that NFS uses portmap!
# you should know that NFS uses portmap!
sshd: ALL
sshd: ALL
</source>
</syntaxhighlight>
:→ 나머지는 모두 ssh 접근 불가
:→ 나머지는 모두 ssh 접근 불가
;[[sshd 재시작]]<ref>CentOS는 <code>service sshd restart</code>, 우분투는 <code>service ssh restart</code></ref>
sshd를 재시작해야 적용된다.
<source lang='console'>
[root@zetawiki ~]# service sshd restart
Stopping sshd:                                            [  OK  ]
Starting sshd:                                            [  OK  ]
</source>


==테스트==
==테스트==
허용되지 않은 IP에서 접속시도시 아래와 같이 접속 실패
허용되지 않은 IP에서 접속시도시 아래와 같이 접속 실패
<source lang='console'>
<syntaxhighlight lang='console'>
[root@zetawiki ~]# ssh root@example.com
[root@zetawiki ~]# ssh root@example.com
ssh_exchange_identification: Connection closed by remote host
ssh_exchange_identification: Connection closed by remote host
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
65번째 줄: 57번째 줄:
*[[iptables]]
*[[iptables]]


==참고 자료==
==참고==
*http://www.phpschool.com/link/qna_other/124298
*http://www.phpschool.com/link/qna_other/124298
*http://hostsmb.com/gnu/bbs/board.php?bo_table=cmp_faq&wr_id=17
*http://hostsmb.com/gnu/bbs/board.php?bo_table=cmp_faq&wr_id=17


[[분류: 리눅스 보안]]
[[분류: 리눅스 보안]]

2021년 9월 24일 (금) 23:19 기준 최신판

특정 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 접근 불가

2 테스트[ | ]

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

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

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}