본문 바로가기

리눅스

우분투 24.04에서 비밀번호 정책 설정 및 계정 잠금 설정하는 방법

반응형

우분투 24.04에서 비밀번호 정책 설정 및 계정 잠금 설정하는 방법

필수 패키지 설치

PAM 모듈을 설치합니다.

sudo apt update
sudo apt install -y libpam-faillock libpam-pwquality
  • libpam-faillock: 로그인 실패 추적 및 계정 잠금
  • libpam-pwquality: 비밀번호 품질 검사

계정 잠금 설정(faillock)

1. 인증(Auth) PAM 설정 수정

sudo vim /etc/pam.d/common-auth
더보기
#
# /etc/pam.d/common-auth - authentication settings common to all services
#
# This file is included from other service-specific PAM config files,
# and should contain a list of the authentication modules that define
# the central authentication scheme for use on the system
# (e.g., /etc/shadow, LDAP, Kerberos, etc.).  The default is to use the
# traditional Unix authentication mechanisms.
#
# As of pam 1.0.1-6, this file is managed by pam-auth-update by default.
# To take advantage of this, it is recommended that you configure any
# local modules either before or after the default block, and use
# pam-auth-update to manage selection of other modules.  See
# pam-auth-update(8) for details.

# here are the per-package modules (the "Primary" block)
auth    [success=1 default=ignore]      pam_unix.so nullok
# here's the fallback if no module succeeds
auth    requisite                       pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
auth    required                        pam_permit.so
# and here are more per-package modules (the "Additional" block)
auth    optional                        pam_cap.so 
# end of pam-auth-update config
auth required pam_faillock.so preauth silent deny=5 unlock_time=300
auth [default=die] pam_faillock.so authfail deny=5 unlock_time=300

최종 결과

# here are the per-package modules (the "Primary" block)
auth required pam_faillock.so preauth silent deny=5 unlock_time=300
auth    [success=1 default=ignore]      pam_unix.so nullok
auth [default=die] pam_faillock.so authfail deny=5 unlock_time=300
# here's the fallback if no module succeeds
auth    requisite                       pam_deny.so

설정 옵션 설명

  • deny=5 : 5회 실패 시 계정 잠금
  • unlock_time=300 : 300초(5분) 후 자동 잠금 해제
  • preauth : 인증 전 실패 횟수 확인
  • authfail : 인증 실패 시 카운트 증가
  • silent : 사용자에게 잠금 메시지 표시 안 함

2. 계정(Account) PAM 설정 수정

sudo vim /etc/pam.d/common-account
더보기
#
# /etc/pam.d/common-account - authorization settings common to all services
#
# This file is included from other service-specific PAM config files,
# and should contain a list of the authorization modules that define
# the central access policy for use on the system.  The default is to
# only deny service to users whose accounts are expired in /etc/shadow.
#
# As of pam 1.0.1-6, this file is managed by pam-auth-update by default.
# To take advantage of this, it is recommended that you configure any
# local modules either before or after the default block, and use
# pam-auth-update to manage selection of other modules.  See
# pam-auth-update(8) for details.
#

# here are the per-package modules (the "Primary" block)
account [success=1 new_authtok_reqd=done default=ignore]        pam_unix.so 
# here's the fallback if no module succeeds
account requisite                       pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
account required                        pam_permit.so
# and here are more per-package modules (the "Additional" block)
# end of pam-auth-update config
account required pam_faillock.so

최종 결과

# here are the per-package modules (the "Primary" block)
account required pam_faillock.so
account [success=1 new_authtok_reqd=done default=ignore]        pam_unix.so 
# here's the fallback if no module succeeds
account requisite                       pam_deny.so
728x90

3. Faillock 상태 확인 및 관리

특정 사용자의 로그인 실패 횟수 확인

faillock --user 사용자명

사용자 계정 잠금 해제

faillock --user 사용자명 --reset

모든 사용자의 잠금 상태 초기화

sudo faillock --reset

비밀번호 복잡도 정책

1. 비밀번호 품질 모듈 활성화

sudo vim /etc/pam.d/common-password
password requisite pam_pwquality.so retry=3
  • requisite : 이 검사를 통과하지 못하면 즉시 실패
  • retry=3 : 비밀번호 입력을 최대 3번까지 재시도 가능

2. 비밀번호 복잡도 규칙 설정

sudo vim /etc/security/pwquality.conf
# 최소 비밀번호 길이
minlen = 8
# 숫자가 최소 1개 이상 포함되어야 함 (음수는 '최소 개수' 의미)
dcredit = -1
# 특수문자가 최소 1개 이상 포함되어야 함
ocredit = -1
# 소문자가 최소 1개 이상 포함되어야 함
lcredit = -1
# 대문자가 최소 1개 이상 포함되어야 함
ucredit = -1
# 동일한 문자가 연속으로 몇 개까지 허용될지 (기본: 0은 제한 없음)
maxrepeat = 3
# 사용자 이름을 포함할 수 없음
usercheck = 1
# 이전 비밀번호와 달라야 하는 문자 개수
difok = 5

주요 설정 옵션

  • minlen : 최소 비밀번호 길이
  • dcredit : 숫자 개수(-N: 최소 N개 필수)
  • ucredit : 대문자 개수
  • lcredit : 소문자 개수
  • ocredit : 특수문자 개수
  • maxrepeat : 연속 동일 문자 제한
  • usercheck : 사용자명 포함 금지
  • difok : 이전 비밀번호와 다른 문자 수
  • minclass : 문자 클래스 최소 개수
dcredit, ucredit, lcredit, ocredit는 음수로 설정해야 "최소 개수"를 의미합니다.
양수는 "최대 보너스 점수"를 의미하므로 헷갈리지 마세요

설정 테스트 및 검증

1. 계정 잠금 테스트

  • 테스트 계정 생성
sudo useradd -m testuser
sudo passwd testuser
  • 의도적으로 5번 로그인 실패 시도
su - testuser
# 잘못된 비밀번호 5번 입력
  • 잠금 상태 확인
sudo faillock --user testuser
  • 잠금 해제
sudo faillock --user testuser --reset

2. 비밀번호 정책 테스트

  • 약한 비밀번호로 변경 시도
sudo passwd testuser
# "12345678" 입력 → 거부되어야 함
# "abcdefgh" 입력 → 숫자/특수문자 없어서 거부
# "Abc123!@" 입력 → 정책 통과

보안 권장 사항

Faillock 강화

# 3회 실패 시 30분 잠금
auth required pam_faillock.so preauth silent deny=3 unlock_time=1800 fail_interval=900

비밀번호 정책 강화

minlen = 14
dcredit = -2
ucredit = -2
lcredit = -2
ocredit = -2
maxrepeat = 2
usercheck = 1
difok = 8
minclass = 4

 

728x90
반응형