selinux + sshd + 2FA

ILOV-IT·2025년 10월 6일

.
.
.
UPSET

1) .ssh 아래에 새 시크릿 생성

sudo -u user -H mkdir -p /home/user/.ssh

sudo -u user -H google-authenticator \
  -t -d -f -r 3 -R 30 -w 3 \
  --secret=/home/user/.ssh/google_authenticator

sudo chown user:user /home/user/.ssh/google_authenticator
sudo chmod 400 /home/user/.ssh/google_authenticator

2) SELinux 컨텍스트 정리

# .ssh 디렉터리와 내부 파일을 정책 기본값으로 라벨링
sudo restorecon -Rv /home/user/.ssh

# 확인
ls -Zd /home/user/.ssh
ls -Z  /home/user/.ssh/google_authenticator
# 둘 다 타입이 ssh_home_t 여야 함

3) PAM에 새 경로 지정

sudo vi /etc/pam.d/sshd
auth required pam_google_authenticator.so nullok secret=${HOME}/.ssh/google_authenticator

4) SSH 설정 확인

sudo vi /etc/ssh/sshd_config
UsePAM yes
PasswordAuthentication yes
ChallengeResponseAuthentication yes

<optional?>
UsePAM yes
KbdInteractiveAuthentication yes
AuthenticationMethods keyboard-interactive

sudo systemctl restart sshd

5) 접속테스트

6) nullok 제거

sudo sed -i 's/ secret=.* nullok/ secret=\/home\/shyim\/\.ssh\/google_authenticator/' /etc/pam.d/sshd
sudo systemctl restart sshd
profile
because we know you'll love it

0개의 댓글