pubkey로만 접근 가능하게 했는데 비번으로도 접근이 가능하다..
| topics | 400-인프라 & 아키텍처 409 리눅스 |
| types | 에러해결 |
| tags | #ssh #linux #security |
환경
SSH 설정에서 비밀번호 인증을 비활성화했는데도 비밀번호로 접근이 가능했다.
~$ sudo vi /etc/ssh/sshd_config
PermitRootLogin no # root 비활성화
PasswordAuthentication no # password 비활성화
PubkeyAuthentication yes # Key authentication 활성화
상황
분명 PasswordAuthentication no로 설정했는데,
sshd_config를 수정해도 계속 비밀번호 인증이 됐다.
확인 + 해결
원인 분석
sudo sshd -T 명령어로 실제 적용되는 옵션을 확인할 수 있다.
sudo sshd -T | grep -i passwordauthentication
sshd_config 파일을 보면 이런 구문이 있다:
Include /etc/ssh/sshd_config.d/*.conf
이게 뭐냐면, sshd_config.d 폴더의 설정이 우선 적용된다는 거다.
확인해보니 50-cloud-init.conf라는 파일이 있었고, 여기서 PasswordAuthentication가 yes로 되어있었다.
해결 방법
sudo vi /etc/ssh/sshd_config.d/50-cloud-init.conf
# PasswordAuthentication yes → no로 변경
PasswordAuthentication no
수정 후 SSH 서비스 재시작:
sudo systemctl restart sshd
왜 이렇게 했냐면: sshd_config보다 sshd_config.d의 설정이 우선 적용되기 때문에, 여기서 수정해야 함.
50-cloud-init.conf는 왜 있는걸까
리눅스가 초기 설정할 때 cloud-init이 이 파일을 생성한다. 클라우드 환경(AWS, GCP 등)에서 인스턴스 초기화 시 자동으로 만들어지는 파일이다.