본문 바로가기
Web Development/Vulnerability

SSHD 접근제어

by 피치피치어피치 2025. 9. 8.
반응형

특정 IP 혹은 유저의 SSH 접속을 제한하고싶을때 아래 3가지 방법으로 제한을 할수 있다.

1. TCP Wrappers 방식 (/etc/hosts.allow, /etc/hosts.deny)

    • 설정 파일 위치
      • /etc/hosts.allow
      • /etc/hosts.deny
    • /etc/hosts.allow → 허용 목록
    • /etc/hosts.deny → 차단 목록
    • 예시:
1
2
3
4
5
6
7
# /etc/hosts.allow
sshd: 192.168.1.100   # 특정 IP 허용
sshd: 192.168.1.0/24  # 특정 대역 허용
 
# /etc/hosts.deny
sshd: ALL             # 나머지 차단
 
cs

 

  • 주의: 최신 배포판(예: CentOS 7, Ubuntu 20.04 이후)은 tcp_wrappers 지원이 빠져서 위 방식이 안 될 수 있음.

2. sshd_config 방식

/etc/ssh/sshd_config 안에 직접 설정.

  • AllowUsers, DenyUsers
  • AllowGroups, DenyGroups
  • 예시:
1
2
3
4
5
6
7
8
9
# 특정 사용자만 허용, 뒤에 아이피는 클라이언트 아이피
AllowUsers admin user1@192.168.1.100
 
# 특정 사용자 차단
DenyUsers testuser
 
# 특정 그룹 허용
AllowGroups sshusers
 
cs

 

3. firewall(방화벽) 방식

  • 예시:
1
2
3
4
5
6
# 특정 IP 허용
firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='192.168.1.100' service name='ssh' accept"
 
# 전체 차단 후 허용된 것만 오픈
firewall-cmd --permanent --remove-service=ssh
 
cs
반응형