sshd_config — SSH 서버 보안 설정
기본 안전 설정
# /etc/ssh/sshd_config
Port 22
# 인증 방식
PubkeyAuthentication yes
PasswordAuthentication no # 비밀번호 로그인 차단
PermitEmptyPasswords no # 빈 비밀번호 차단
# root 직접 로그인 차단
PermitRootLogin no
# 로그인 시도 제한
MaxAuthTries 3 # 3번 틀리면 차단
LoginGraceTime 30 # 30초 안에 인증 안 하면 끊김
# 유휴 연결 관리
ClientAliveInterval 300 # 5분마다 연결 확인
ClientAliveCountMax 2 # 2번 응답 없으면 끊김
# 기타
X11Forwarding no
AllowTcpForwarding yes # code-server 포트 포워딩 필요시
설정 적용
# 문법 오류 확인 먼저
sudo sshd -t
# 문제 없으면 재시작
sudo systemctl restart sshd
기본값 동작
설정이 명시되지 않으면 SSH 기본값이 적용됨:
| 설정 | 기본값 | |---|---| | PubkeyAuthentication | yes | | PasswordAuthentication | yes |
즉 아무것도 안 쓰면 key + 비밀번호 둘 다 허용.
포트 22 주의사항
포트 22는 전 세계에서 brute force 공격이 집중됨. PasswordAuthentication no가 핵심 방어선.
추가 방어: fail2ban 설치
sudo apt install fail2ban
sudo systemctl enable fail2ban
일정 횟수 이상 실패한 IP를 자동 차단.
임시 접근 워크플로우
평소: PasswordAuthentication no (key만 허용)
임시: authorized_keys에 상대방 key 추가 → 기간 후 삭제
sshd_config는 건드리지 않는 게 깔끔함.
연결 개념
- ssh-key-auth — client 측 key 설정 및 등록