[목차]

 

 

1. PAM 이론

2. PAM 관련 실습

3. 정리 : CentOS 7.0 이상에서 암호 설정 변경

 

 

출처 : 솔데스크 백승찬 강사님

 

 

 


 

 

 

[PAM 이론]

 

 

 

(1) PAM (Pluggable Authentication Modules, 착탈형 인증 모듈) 이란?

 

시스템 관리자가 응용프로그램들이 사용자를 인증하는 방법을 선택할 수 있도록 해 주는 공유 라이브러리 묶음이다. 즉, 사용자를 인증하고 그 사용자의 서비스에 대한 액세스를 제어하는 모듈화된 방법을 말한다. PAM은 관리자가 응용프로그램들의 사용자 인증 방법을 선택할 수 있도록 해 준다. 필요한 공유라이브러리의 묶음을 제공하여 PAM을 사용하는 응용프로그램을 재컴파일없이 인증 방법을 변경할 수 있다.

 

 

PAM은 시스템 관리자가 시스템의 인증 정책을 설정할 때 상당히 유연성을 제공하는 플러그 가능한 모듈러 아키텍쳐를 사용한다. PAM은 여러가지 이유로 개발자와 관리자에게 유용한 기술이다.

PAM은 다양한 응용 프로그램과 함께 사용할 수 있는 공통 인증체계를 제공한다.

PAM은 시스템 관리자와 응용 프로그램 개발자 모두에게 상당한 유연성과 인증 제어 기능을 제공한다.

PAM은 개발자가 자신의 인증 스키마를 만들지 않고도 프로그램을 작성할 수 있게 해주는 완벽하게 문서화 된 단일 라이브러리를 제공한다.

 

 

PAM aware App.

PAM library

PAM File

PAM Module

/bin/su

/lib/libpam.so.0

/etc/pam.d/su

/lib/security/*

 

 

 

 

(2) PAM 목적과 동작

 

"리눅스-PAM프로젝트의 목적은 안전하고 적합한 인증방법의 개발과 소프트웨어에게 부여한 특권의 개발을 분리하는 것이다"라고 되어 있다. 이것은 사용자가 인증되어야 한다는 요청하기 위해 어떤 응용프로그램이 사용할 수 있는 함수의 라이브러리를 제공함으로써 가능하다. PAM 라이브러리는 /etc/pam.d(또는 /etc/pam.conf)에서 각 시스템에 맞게 설정하여, 각 시스템에서 사용가능한 인증 모듈을 통해 사용자의 인증 요구를 처리한다. 모듈 자체는 /lib/security(또는 /usr/lib/security)에 위치하고 동적으로 로드가능한 오프젝트 파일의 형태를 갖는다.

 

 

 

 

(3) PAM 구성 파일

 

/etc/pam.d/<PAM 파일>(또는 /etc/pam.conf)

 

<PAM 파일>이 서비스 이름이다. 주로 해당 응용프로그램의 일반적인 이름을 사용한다.

예를 들어 'ftpd', 'rlogind', 'su' 등이다.

 

기본 인증 방법을 정의학 위해 정의된 특별한 서비스 other 이름도 존재한다.

만약 어떤 서비스의 인증 모듈 설정이 되어 있다면 'other' 항목은 무시된다.

 

 

 

 

 

(4) PAM 구성 파일의 문법

-------------------------------------------------------------

type control module-path module-arguments

-------------------------------------------------------------

 

■ type(모듈 종류(module type), 모듈 인터페이스(module interface))

타입토큰은 PAM에 이 모듈에 어떤 타입의 인증이 사용될 것인지를 알려준다. 같은 타입의 모듈은 "쌓일" 수 있고, 사용자에 인증되기 위한 다중 요구사항을 만족하도록 요청할 수 있다. PAM은 네개의 타입을 인식한다.

 

 

 

다음과 같이 4개의 종류(Module Type, Module Interface)로 구성되어 있다.

 

종류

설명

auth

이 모듈 인터페이스는 사용을 인증한다. 예를 들어 암호의 유효성을 요청하고 검증한다. 이 모듈을 사용하여 그룹 구성원 자격 또는 Kerberos 티켓과 같은 자격 증명을 설정할수도 있다.

주로 패스워드를 통하지만 생체인증과 같은 보다 정교한 방법을 통해서 사용자가 자신이 주장하는 사용자가 맞는지 결정한다.

인증이 아닌 계정 관리를 수행한다. 이것은 보통 시간/날짜 현재의 시스템 자원 상황(최대 사용자수)이나 사용자의 위치(root는 콘솔에서만 로그인이 가능하다)등에 따라 서비스에 대한 접근을 허가하거나 제한하는 것이다.

account

이 모듈 인터페이스는 액세스가 허용되는지 확인한다. 예를 들어 사용자 계정이 만료되었는지 또는 특정 시간대에 사용자가 로그인할 수 있는지 여부를 확인한다.

계정(account)은 사용자가 해당 서비스에 접근이 허용되었는지, 패스워드가 기간이 만료가 되었는지를 결정한다.

사용자 인증의 두가지 면을 제공한다. 첫번째는, 응용프로그램이 사용자에게 패스워드를 물어보거나 다른 확인 방법을 사용하도록 해서 그 사용자가 자신이 주장하는 사람이 맞는지 확인하는 것이다. 두번째는, 그룹 멥버쉽을 주거나 credential(신임)속성을 통해 다른 권한을 주는것이다.

password

이 모듈 인터페이스는 사용자 암호를 변경하는데 사용한다.

패스워드는 사용자가 그들의 인증을 변경하도록 어떤 방법을 제공한다. 이것은 주로 패스워드이다. 사용자와 연관된 인증토큰(패스워드)들을 갱신할 때 필요하다.

보통 challenge/response 방식에 기반한 인증모듈 종류별로 각각 하나의 password 모듈씩이 존재한다.

session

이 모듈 인터페이스는 사용자 세션을 구성하고 관리한다. 이 인터페이스가 있는 모듈은 사용자의 홈디렉토리를 마운트하고 사용자의 사서함을 사용할 수 있게 하는등 액세스를 허용하는데 필요한 추가 작업을 수행할수도 있다.

이것은 사용자 홈 디렉토리를 마운팅/언마우팅하는 것과 로그인/로그아웃 그리고 사용자에게 제공하는 서비스를 제한/제공하는 것과 같은 것을 포함할 수 있다.

 

 

 

 

■ control(제어 플래그)

모든 PAM 모듈은 호출 될때 성공 또는 실패 결과를 생성한다. 제어 플래그는 PAM에 결과와 어떤 관계가 있는지 알려준다. 모듈은 특정 순서로 스택 될 수 있으며, 제어 플래그는 특정 모듈의 성공 또는 실패가 사용자를 서비스에 인증하는 전체 목표에 얼마나 중요한지 결정한다.

PAM은 네가지의 통제 형식을 인식한다.

 

종류

설명

requisite

(필수: 모듈 결과가 성공하면 다음 라인으로 넘어가고, 모듈 결과가 실패하면 첫번째 실패 required 또는 requisite 모듈 테스트를 반영한 메세지를 반환한다.) 인증을 계속하려면 모듈 결과가 성공해야 한다. 그러나, 이 시점에서 테스트가 실패하면 사용자는 첫번째 실패 required 또는 requisite 모듈 테스트를 반영하는 메세지를 즉시 통보한다. 다시 말해서, 이 모듈을 이용하는 인증이 실패할 경우, 즉시 인증을 거부하도록 한다. 사용자가 안전하지 않은 매체(media)에서 패스워드를 입력할 경우에 대비해 사용할 수 있다. 이러한 행동은 크래커에게 시스템의 유효한 계정을 알려줄 수 있다. 이 가능성은 민감한 패스워드를 적대적인 환경에 노출시키는 것에 대한 사소하지 않은 염려와 비교해서 검토해야 한다.

required

(필요: 모듈 결과가 성공하면 다음 라인으로 넘어가고, 모듈 결과가 실패해도 다음 라인으로 넘어가서 성공하지 않은 경우의 최종결과는 실패이다.) 인증을 계속하려면 모듈 결과가 성공해야 한다. 이 시점에서 테스트가 실패하면 해당 인터페이스를 참조하는 모든 모듈 테스트의 결과가 완료 될때까지 사용자에게 알리지 않는다. required 모듈이 호출되는 순서는 중요하지 않다. 플래그 sufficient 및 requisite 제어 플래그만이 명령을 중요하게 만든다.

sufficient

(충분: 모듈 결과가 성공하였고 이전 required가 실패하지 않은 경우 서비스에 대해 인증되고, 모듈 결과가 실패하면 다음라인으로 넘어간다.) 모듈 결과가 실패하면 무시된다. 그러나 플래그 sufficient가 지정된 모듈의 결과가 성공적이며, 플래그 된 이전 모듈 required가 실패하지 않은 경우 다른 결과는 필요하지 않으며, 사용자는 서비스에 대해 인증된다.

optional

(옵션: 다른 모듈의 성공/실패가 없는 경우 optional 모듈의 결과로 결정된다. 하지만, 다른 모듈의 성공/실패가 있다면, optional 모듈의 결과는 무시된다.) 이 모듈이 성공 또는 실패하는지는 그 모듈이 서비스에 대한 형식에 대한 유일한 모듈일 경우에 중요하다. 보통 PAM은 모듈의 성공/실패 판단시에 이런 모듈을 무시한다. 그러나 이전/이후의 모듈들이 명확한 성공/실패가 없다면 이 모듈이 응용그램에게 주는 결과로 결정짓는다.

include

(포함: PAM 파일을 지정할 때 사용한다.) 다른 컨트롤과 달리 모듈 결과가 처리되는 방식과 관련이 없다. 이 플래그는 지정된 매개 변수와 일치하는 구성 파일의 모든 행을 가져와서 모듈에 인수로 추가한다.



 

■ module-path(모듈 경로)

 

모듈경로는 PAM에게 어떤 모듈을 사용할 것인지(선택적으로) 그리고 그것을 어디서 찾을 지를 알려준다. 대부분 구성은 로그인 구성파일의 경우와 마찬가지로 모듈의 이름만 가지고 있다. 이와 같은 경우, PAM은 기본 PAM 모듈의 디렉토리에서(보통 /usr/lib/security) 모듈을 찾는다. 그러나 여러분의 리눅스가 리눅스 파일시스템의 표준을 따른다면 PAM 모듈은 /lib/security에 있다.

 

# cd /lib/security

# ls

pam_access.so pam_keyinit.so pam_permit.so pam_tally.so

pam_ccreds.so pam_krb5 pam_pkcs11.so pam_time.so

pam_chroot.so pam_krb5afs.so pam_postgresok.so pam_timestamp.so

pam_console.so pam_krb5.so pam_pwhistory.so pam_tty_audit.so

pam_cracklib.so pam_lastlog.so pam_rhosts_auth.so pam_umask.so

pam_debug.so pam_ldap.so pam_rhosts.so pam_unix_acct.so

pam_deny.so pam_limits.so pam_rootok.so pam_unix_auth.so

pam_echo.so pam_listfile.so pam_rps.so pam_unix_passwd.so

pam_ecryptfs.so pam_localuser.so pam_securetty.so pam_unix_session.so

pam_env.so pam_loginuid.so pam_selinux.so pam_unix.so

pam_exec.so pam_mail.so pam_shells.so pam_userdb.so

pam_faildelay.so pam_mkhomedir.so pam_smb_auth.so pam_warn.so

pam_filter pam_motd.so pam_smbpass.so pam_wheel.so

pam_filter.so pam_namespace.so pam_stack.so pam_winbind.so

pam_ftp.so pam_nologin.so pam_stress.so pam_xauth.so

pam_group.so pam_oddjob_mkhomedir.so pam_succeed_if.so

pam_issue.so pam_passwdqc.so pam_tally2.so



■ module-arguments(모듈 인수)

 

모듈-인수는 모듈에게 전달되는 인수이다. 각각의 모듈은 각각의 인수를 가지고 있다. 예를 들어 로그인 구성에서 "nullok"가 그것이다. ("null ok", pam_unix.so 모듈로 전달되어 지는 인수로서 공백(null)패스워드를 허용한다는 것이다("ok")).

 

잘못된 모듈인수는 무시되며, PAM 모듈의 성공 또는 실패에는 영향을 주지 않는다. 그러나 일부 모듈은 잘못된 인수로 인해 실패할 수 있다. 대부분의 모듈은 /var/log/secure 파일에 오류를 보고한다.

 

# man pam_wheel

SYNOPSIS

pam_wheel.so [debug] [deny] [group=name] [root_only] [trust] [use_uid]

 

# cat /etc/pam.d/su

#%PAM-1.0

auth sufficient pam_rootok.so

# Uncomment the following line to implicitly trust users in the "wheel" group.

#auth sufficient pam_wheel.so trust use_uid

# Uncomment the following line to require a user to be in the "wheel" group.

#auth required pam_wheel.so use_uid

auth include system-auth

account sufficient pam_succeed_if.so uid = 0 use_uid quiet

account include system-auth

password include system-auth

session include system-auth

session optional pam_xauth.so

 

 

 

 

 

(5) PAM 파일

 

(1) 샘플 PAM 파일(EX: login)의 예제와 해석

1

2

3

4

5

6

7

8

#%PAM-1.0

auth required pam_securetty.so

auth required pam_unix.so nullok

auth required pam_nologin.so

account required pam_unix.so

password required pam_cracklib.so retry=3

password required pam_unix.so shadow nullok use_authtok

session required pam_unix.so


(샘플 PAM 파일 해석)

auth required pam_securetty.so

root 사용자가 로그인을 시도하는 경우 /etc/securetty 파일을 보고, root 사용자에게 허용될수 있는 터미널을 확인한다. 파일에 tty가 나열되어 있지 않으면, 로그인을 시도는 'Login incorrect' 메세지와 함께 실패한다. 만약 일반 사용자라면 이 모듈은 무시된다.

 

auth required pam_unix.so nullok

사용자에게 암호를 묻는 메세지를 표시한 다음 /etc/passwd, /etc/shadow 파일에 저장된 정보를 확인한다. nullok는 암호에 공백을 허용하도록 하는 인자값이다.

 

auth required pam_nologin.so

/etc/nologin 파일이 있는지 여부를 확인하고, 파일이 없으면 인증에 성공하고, 파일이 있으면서 root 사용자가 아니라면 인증에 실패한다. root 사용자는 /etc/nologin 파일이 있어도 로그인 가능하다.

첫번째 auth 모듈이 실패하도라도 세개의 모듈 전부를 확인한다.(pam_securetty.so, pam_unix.so, pam_nologin.so)

 

account required pam_unix.so

필요한 계정 확인을 수행한다. 예를 들어 새도우 암호가 활성화 된 경우, 계정이 만료되었거나 사용자가 허용된 유예기간내에 암호를 변경하지 않았는지 확인한다.

 

password required pam_cracklib.so retry=3

암호가 만료된 경우 pam_cracklib.so 모듈의 암호 구성요소는 새 암호를 묻는 메시지를 표시한다. 그런 다음 새로 생성된 암호를 테스트하여 사전 기반 암호 해독 프로그램에서 쉽게 확인할 수 있는지 여부를 확인한다. retry=3는 테스트가 처음 실패한 경우 사용자가 강력한 암호를 작성할 기회가 2번 더 있음을 나타낸다.

password required pam_unix.so shadow nullok use_authok

사용자가 암호를 변경하는 경우의 지정이다. shadow는 사용자 암호를 업데이트 할 때 새도우 암호를 만들도록 모듈에 지시하는 인자이다. nullok는 모듈이 빈 암호로 변경할 수 있도록 지시하는 인자이다. nullok 인자가 없다면, 빈 암호(Null password)는 계정 잠금으로 처리된다. use_authok는 사용자에게 새 암호를 입력하라는 메시지를 표시 하도록 지시하는 인자이다. 이전 암호 모듈에 의해 기록된 암호를 승인한다. 이런식으로 모든 새 암호는 pam_cracklib.so 승인되기 전에 보안 암호에 대한 테스트를 통과해야 한다.

 

session required pam_unix.so

/var/log/secure 파일에 각 세션의 시작과 끝에 사용자 이름과 서비스 유형을 기록한다.

이 모듈은 추가 기능을 위해 다른 세션 모듈과 겹침으로써 보완 될수 있다.

 

 

■ 대표적인 PAM 파일

/etc/pam.d/login 파일

/etc/pam.d/other 파일

 

 

■ /etc/pam.d/login 파일

# cd /etc/pam.d

# ls

atd passwd system-auth-ac

authconfig pirut system-cdinstall-helper

authconfig-gtk pm-hibernate system-config-authentication

authconfig-tui pm-powersave system-config-date

chfn pm-suspend system-config-display

chsh pm-suspend-hybrid system-config-httpd

config-util poweroff system-config-kdump

cpufreq-selector ppp system-config-keyboard

crond pup system-config-language

cups reboot system-config-lvm

dateconfig remote system-config-netboot

dovecot run_init system-config-network

eject runuser system-config-network-cmd

ekshell runuser-l system-config-nfs

gdm sabayon system-config-printer

gdm-autologin samba system-config-rootpassword

gdmsetup seaudit system-config-samba

gnome-screensaver serviceconf system-config-securitylevel

gnome-system-log setup system-config-selinux

gssftp smtp system-config-services

halt smtp.sendmail system-config-soundcard

kbdrate squid system-config-time

kshell sshd system-config-users

ksu su system-install-packages

login su-l vmtoolsd

neat sudo vsftpd

newrole sudo-i wireshark

other system-auth xserver

 

 

# cat /etc/pam.d/login

#%PAM-1.0

auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so

/* pam_securetty.so 모듈이 지정해 놓은 보안 규칙을 만족해야만 로그인이 허용된다는 설정이다. 이 모듈은 /etc/securetty 파일에서 지정되어 있는 tty에서 요청한 슈퍼유저만 로그인을 허용한다. */

auth include system-auth

account required pam_nologin.so

account include system-auth

password include system-auth

# pam_selinux.so close should be the first session rule

session required pam_selinux.so close

session optional pam_keyinit.so force revoke

session required pam_loginuid.so

session include system-auth

session optional pam_console.so

# pam_selinux.so open should only be followed by sessions to be executed in the user context

session required pam_selinux.so open

 

auth 부분을 확인해 보면 system-auth 파일을 참조하는 것을 확인할 수 있다. 따라서 system-auth 파일안의 내용 중에 auth 부분을 확인해야 한다.

account 부분도 system-auth 파일을 참조하고 있다.

password 부분도 system-auth 파일을 참조하고 있다.

 

 

■ /etc/pam.d/other

PAM에서 별도로 지정하지 않은 서비스에 대한 인증을 위한 참조하는 파일이다.

 

# cat /etc/pam.d/other

#%PAM-1.0

auth required pam_deny.so

account required pam_deny.so

password required pam_deny.so

session required pam_deny.so

/* 지정되지 않은 서비스가 4개의 구성타입 중 어떤 곳에 접근을 시도하더라도 PAM은 인증을 거부한다. (pam_deny.so 모듈이 담당한다.) */


PAM 파일을 해석하기 위해서는 PAM 모듈의 기능과 인자에 대한 부분을 이해해야 한다.

 

 

 

 

 

 

(6) 주요 PAM 모듈

 

■ 주요 PAM 모듈

/lib/security/pam_securetty.so 모듈

/lib/security/pam_listfile.so 모듈

/lib/security/nologin.so 모듈

/lib/security/pam_deny.so 모듈

/lib/security/pam_cracklib.so 모듈 -> pam_pwquality.so(CentOS 7.x 이상)

/lib/security/pam_wheel.so 모듈

/lib/security/pam_rootok.so 모듈

/lib/security/pam_tally.so 모듈 -> pam_faillock.so(CentOS 7.x 이상)

/lib/security/pam_tally2.so 모듈

 

 

■ 모듈 디렉토리(EX: /lib/security)와 PAM 모듈 종류 확인

 

라이브러리(Library)

- 정적 라이브러리 : A.o

- 동적 라이브러리 : A.so

# ldd /bin/ls

# pmap PID

 

# cd /lib/security (# cd /usr/lib64/security)

# ls

pam_access.so pam_krb5 pam_pkcs11.so pam_time.so

pam_ccreds.so pam_krb5.so pam_postgresok.so pam_timestamp.so

pam_chroot.so pam_krb5afs.so pam_pwhistory.so pam_tty_audit.so

pam_console.so pam_lastlog.so pam_rhosts.so pam_umask.so

pam_cracklib.so pam_ldap.so pam_rhosts_auth.so pam_unix.so

pam_debug.so pam_limits.so pam_rootok.so pam_unix_acct.so

pam_deny.so pam_listfile.so pam_rps.so pam_unix_auth.so

pam_echo.so pam_localuser.so pam_securetty.so pam_unix_passwd.so

pam_env.so pam_loginuid.so pam_selinux.so pam_unix_session.so

pam_exec.so pam_mail.so pam_shells.so pam_userdb.so

pam_faildelay.so pam_mkhomedir.so pam_smb_auth.so pam_warn.so

pam_filter pam_motd.so pam_smbpass.so pam_wheel.so

pam_filter.so pam_namespace.so pam_stack.so pam_winbind.so

pam_ftp.so pam_nologin.so pam_stress.so pam_xauth.so

pam_group.so pam_oddjob_mkhomedir.so pam_succeed_if.so

pam_issue.so pam_passwdqc.so pam_tally.so

pam_keyinit.so pam_permit.so pam_tally2.so

 

많은 PAM 모듈 파일들이 존재하는 것을 확인할 수 있다.

이 중에서도 보안상 많이 다루어지는 PAM 모듈은

- pam_cracklib.so

- pam_wheel.so

- pam_tally.so

- pam_tally2.so

등이다.

 

 

PAM 모듈에 대한 자세한 정보 확인하는 방법

(ㄱ) 매뉴얼 검색하는 방법

pam_cracklib.so --> # man pam_cracklib (# info pam_cracklib)

(ㄴ) /usr/share/doc/pam-*/

# cd /usr/share/doc/pam-*/

(ㄷ) 인터넷 통해 검색하는 방법

http://docs.redhat.com -> RHEL 문서 중 PAM 문서

KLDP(Korean Linux Documentation Projection)

 

 

 

■ /lib/security/pam_securetty.so 모듈

# man pam_securetty

NAME

pam_securetty - Limit root login to special devices

 

SYNOPSIS

pam_securetty.so [debug]

 

DESCRIPTION

pam_securetty is a PAM module that allows root logins only if the

user is logging in on a "secure" tty, as defined by the listing in

/etc/securetty. pam_securetty also checks to make sure that

/etc/securetty is a plain file and not world writable.

 

This module has no effect on non-root users and requires that the

application fills in the PAM_TTY item correctly.

 

For canonical usage, should be listed as a required authentication

method before any sufficient authentication methods.

 

EXAMPLES

auth required pam_securetty.so

auth required pam_unix.so

 

 

(모듈 설명)

root 사용자로 로그인할 때 사용할 수 있는 장치를 제한할 때 사용한다.

표준 UNIX securetty 검사해서 /etc/securetty 파일에 기록된 내용과 비교하는데 root 계정인 경우에만 확인한다. 그 외의 다른 사용자에 대해서는 항상 인증이 성공한 것으로 처리한다.

다른 sufficient 인증 방법보다 앞서 require 인증방법으로 등록하는 것이 표준 사용방식이다.

 

 

[EX] pam_securetty.so PAM 모듈을 사용하는 PAM 파일들 찾기

# find /etc/pam.d -type f -exec grep -l securetty.so {} \;

/etc/pam.d/ekshell

/etc/pam.d/kshell

/etc/pam.d/login

/etc/pam.d/remote

 

 

# cat /etc/pam.d/login

#%PAM-1.0

auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so

auth include system-auth

account required pam_nologin.so

account include system-auth

password include system-auth

# pam_selinux.so close should be the first session rule

session required pam_selinux.so close

session optional pam_keyinit.so force revoke

session required pam_loginuid.so

session include system-auth

session optional pam_console.so

# pam_selinux.so open should only be followed by sessions to be executed in the user context

session required pam_selinux.so open

 

 

 

 

■ /lib/security/pam_listfile.so 모듈

# man pam_listfile

NAME

pam_listfile - deny or allow services based on an arbitrary file

 

SYNOPSIS

pam_listfile.so item=[tty|user|rhost|ruser|group|shell]

sense=[allow|deny] file=/path/filename

onerr=[succeed|fail] [apply=[user|@group]]

 

DESCRIPTION

pam_listfile is a PAM module which provides a way to deny or allow

services based on an arbitrary file.

 

The module gets the item of the type specified -- user specifies

the username, PAM_USER; tty specifies the name of the terminal over

which the request has been made, PAM_TTY; rhost specifies the name

of the remote host (if any) from which the request was made,

PAM_RHOST; and ruser specifies the name of the remote user (if

available) who made the request, PAM_RUSER -- and looks for an

instance of that item in the file=filename. filename contains one

line per item listed. If the item is found, then if sense=allow,

PAM_SUCCESS is returned, causing the authorization request to

succeed; else if sense=deny, PAM_AUTH_ERR is returned, causing the

authorization request to fail.

 

If an error is encountered (for instance, if filename does not

exist, or a poorly-constructed argument is encountered), then if

onerr=succeed, PAM_SUCCESS is returned, otherwise if onerr=fail,

PAM_AUTH_ERR or PAM_SERVICE_ERR (as appropriate) will be returned.

 

An additional argument, apply=, can be used to restrict the

application of the above to a specific user (apply=username) or a

given group (apply=@groupname). This added restriction is only

meaningful when used with the tty, rhost and shell items.

 

Besides this last one, all arguments should be specified; do not

count on any default behavior.

 

No credentials are awarded by this module.

 

OPTIONS

item=[tty|user|rhost|ruser|group|shell]

What is listed in the file and should be checked for.

 

sense=[allow|deny]

Action to take if found in file, if the item is NOT found in the

file, then the opposite action is requested.

 

file=/path/filename

File containing one item per line. The file needs to be a plain

file and not world writeable.

 

onerr=[succeed|fail]

What to do if something weird happens like being unable to open

the file.

 

apply=[user|@group]

Restrict the user class for which the restriction apply. Note

that with item=[user|ruser|group] this oes not make sense, but

for item=[tty|rhost|shell] it have a meaning.

 

EXAMPLES

Classic 'ftpusers' authentication can be implemented with this

entry in /etc/pam.d/ftpd:

 

#

# deny ftp-access to users listed in the /etc/ftpusers file

#

auth required pam_listfile.so \

onerr=succeed item=user sense=deny file=/etc/ftpusers

 

Note, users listed in /etc/ftpusers file are (counterintuitively)

not allowed access to the ftp service.

 

To allow login access only for certain users, you can use a

/etc/pam.d/login entry like this:

 

#

# permit login to users listed in /etc/loginusers

#

auth required pam_listfile.so \

onerr=fail item=user sense=allow file=/etc/loginusers

 

For this example to work, all users who are allowed to use the

login service should be listed in the file /etc/loginusers. Unless

you are explicitly trying to lock out root, make sure that when you

do this, you leave a way for root to log in, either by listing root

in /etc/loginusers, or by listing a user who is able to su to the

 

 

모듈 설명

임의의 파일에 대한 서비스를 허가하거나 거부하는 방법을 제공한다.

 

 

모듈 인자

onerr=[succeed|fail]

onerr=succeed 이면 PAM_SUCCESS를 리턴하고, onerr=fail이면 PAM_AUTH_ERR

또는 PAM_SERVICE_ERR이 리턴된다. 보통 sense와 반대로 적는다.

file=filename

지정한 파일을 읽는다. 한줄에 한 아이템만 적는다.(EX: file=/etc/vsftpd/ftpusers)

sense=allow|deny

allow는 특정한 아이템이 벌견되면 PAM_SUCCESS가 리턴되고 권한요구는 성공한다. 값이 deny이면 PAM_AUTH_ERR이 리턴되고 권한요구는 실패한다.

item=user|tty|rhost|ruser|group|shell

아이템을 지정한다. 각각 사용자명, 요청한 터미널, 원격사용자, 그룹, 쉘을 나타낸다.

apply=user|@group

특정사용자 또는 주어진 그룹으로 적용을 제한하는데 사용한다. 이것은 tty, rhosts, shell 아이템과 함께 사용될 때만 의미가 있는 제한이다. 생성시에 이 모듈인자를 제외하고는 모듈인자는 필수적이다.

 

 

[EX] 모듈을 사용하는 PAM 파일 찾기

# find /etc/pam.d -type f -exec grep -l pam_listfile.so {} \;

/etc/pam.d/gssftp

/etc/pam.d/vsftpd


# cat /etc/pam.d/vsftpd

#%PAM-1.0

session optional pam_keyinit.so force revoke

auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed

auth required pam_shells.so

auth include system-auth

account include system-auth

session include system-auth

session required pam_loginuid.so

 

 

 

 

 

 

■ /lib/security/nologin.so 모듈

# man pam_nologin

NAME

pam_nologin - Prevent non-root users from login

 

SYNOPSIS

pam_nologin.so [file=/path/nologin] [successok]

 

DESCRIPTION

pam_nologin is a PAM module that prevents users from logging into the

system when /etc/nologin exists. The contents of the /etc/nologin file are

displayed to the user. The pam_nologin module has no effect on the root

user’s ability to log in.

 

OPTIONS

file=/path/nologin

Use this file instead the default /etc/nologin.

 

successok

Return PAM_SUCCESS if no file exists, the default is PAM_IGNORE.

 

EXAMPLES

The suggested usage for /etc/pam.d/login is:

 

auth required pam_nologin.so

 

NOTES

In order to make this module effective, all login methods should be

secured by it. It should be used as a required method listed before any

sufficient methods in order to get standard Unix nologin semantics. Note,

the use of successok module argument causes the module to return

PAM_SUCCESS and as such would break such a configuration - failing

sufficient modules would lead to a successful login because the nologin

module succeeded.


모듈 설명

/etc/nologin 파일이 존재하면 root만 로그인할 수 있고, 다른 사용자는 에러메세지와 함께 거부된다. /etc/nologin 파일이 없다면 모듈은 성공을 리턴한다.

이 모듈을 효과적으로 사용하려면 모든 login 방법들(login, rlogin 등)이 이것을 사용하게 해야 한다.

이 설정은 sufficient 모듈 앞에 required로 설정해야 한다.

 

 

[EX] 모듈을 사용하는 PAM 파일 찾기

# find /etc/pam.d -type f -exec grep -l nologin.so {} \;

/etc/pam.d/login

/etc/pam.d/gssftp

/etc/pam.d/dovecot

/etc/pam.d/gdm

/etc/pam.d/remote

/etc/pam.d/samba

/etc/pam.d/gdm-autologin

/etc/pam.d/ekshell

/etc/pam.d/sshd

/etc/pam.d/ppp

/etc/pam.d/kshell

 

 

# vi /etc/pam.d/login

#%PAM-1.0

auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so

auth include system-auth

account required pam_nologin.so

account include system-auth

password include system-auth

# pam_selinux.so close should be the first session rule

session required pam_selinux.so close

session include system-auth

session required pam_loginuid.so

session optional pam_console.so

# pam_selinux.so open should only be followed by sessions to be executed in the user context

session required pam_selinux.so open

session optional pam_keyinit.so force revoke

 

 

 

 

■ /lib/security/pam_deny.so 모듈

# man pam_deny

NAME

pam_deny - The locking-out PAM module

 

SYNOPSIS

pam_deny.so

 

DESCRIPTION

This module can be used to deny access. It always indicates a failure to

the application through the PAM framework. It might be suitable for using

for default (the OTHER) entries.

 

OPTIONS

This module does not recognice any options.

 

MODULE SERVICES PROVIDED

All services (account, auth, password and session) are supported.

 

EXAMPLES

#%PAM-1.0

#

# If we don’t have config entries for a service, the

# OTHER entries are used. To be secure, warn and deny

# access to everything.

other auth required pam_warn.so

other auth required pam_deny.so

other account required pam_warn.so

other account required pam_deny.so

other password required pam_warn.so

other password required pam_deny.so

other session required pam_warn.so

other session required pam_deny.so


모듈설명

이 모듈은 접근을 거부하는 데 사용한다. 응용프로그램에게 항상 실패를 리턴한다.

 

 

[EX] 모듈을 사용하는 PAM 파일 찾기

# find /etc/pam.d -type f -exec grep -l pam_deny.so {} \

/etc/pam.d/other

/etc/pam.d/system-auth-ac

 

 

# vi /etc/pam.d/other

#%PAM-1.0

auth required pam_deny.so

account required pam_deny.so

password required pam_deny.so

session required pam_deny.so



 

■ /lib/security/pam_cracklib.so 모듈

# man pam_cracklib

NAME

pam_cracklib - PAM module to check the password against dictionary words

 

SYNOPSIS

pam_cracklib.so [...]

 

DESCRIPTION

This module can be plugged into the password stack of a given application

to provide some plug-in strength-checking for passwords.

 

The action of this module is to prompt the user for a password and check

its strength against a system dictionary and a set of rules for

identifying poor choices.

 

The first action is to prompt for a single password, check its strength

and then, if it is considered strong, prompt for the password a second

time (to verify that it was typed correctly on the first occasion). All

being well, the password is passed on to subsequent modules to be

installed as the new authentication token.

 

OPTIONS

debug This option makes the module write information to syslog(3)

indicating the behavior of the module (this option does not write

password information to the log file).

 

type=XXX

The default action is for the module to use the following prompts

when requesting passwords: "New UNIX password: " and "Retype UNIX

password: ". The default word UNIX can be replaced with this

option.

 

retry=N

Prompt user at most N times before returning with error. The

default is 1

 

minlen=N

The minimum acceptable size for the new password (plus one if

credits are not disabled which is the default). In addition to the

number of characters in the new password, credit (of +1 in length)

is given for each different kind of character (other, upper, lower

and digit). The default for this parameter is 9 which is good for a

old style UNIX password all of the same type of character but may

be too low to exploit the added security of a md5 system. Note that

there is a pair of length limits in Cracklib itself, a "way too

short" limit of 4 which is hard coded in and a defined limit (6)

that will be checked without reference to minlen. If you want to

allow passwords as short as 5 characters you should not use this

module.

 

dcredit=N

(N >= 0) This is the maximum credit for having digits in the new

password. If you have less than or N digits, each digit will count

+1 towards meeting the current minlen value. The default for

dcredit is 1 which is the recommended value for minlen less than

10.

 

(N < 0) This is the minimum number of digits that must be met for a

new password.

 

ucredit=N

(N >= 0) This is the maximum credit for having upper case letters

in the new password. If you have less than or N upper case letters

each letter will count +1 towards meeting the current minlen value.

The default for ucredit is 1 which is the recommended value for

minlen less than 10.

 

(N < 0) This is the minimum number of upper case letters that must

be met for a new password.

 

lcredit=N

(N >= 0) This is the maximum credit for having lower case letters

in the new password. If you have less than or N lower case letters,

each letter will count +1 towards meeting the current minlen value.

The default for lcredit is 1 which is the recommended value for

minlen less than 10.

 

(N < 0) This is the minimum number of lower case letters that must

be met for a new password.

 

minclass=N

The minimum number of required classes of characters for the new

password. The default number is zero. The four classes are digits,

upper and lower letters and other characters. The difference to the

credit check is that a specific class if of characters is not

required. Instead N out of four of the classes are required.

 

maxrepeat=N

Reject passwords which contain more than N same consecutive

characters. The default is 0 which means that this check is

disabled.



모듈 설명

이 모듈은 password를 설정한 정책과 비교, 검사 한다. 나쁜 패스워드를 알아내기 위해 사용자에게 패스워드를 묻고, 시스템 사전과 몇가지 규칙으로 패스워드의 튼튼함을 검사한다.

 

모듈 동작 방법

새로운 암호와 이전 암호가 회문(palindrome) 형태로 되어 있는지 확인

새로운 암호와 이전 암호가 대소문자만 변경된 것이 아닌가 확인

새로운 암호와 이전 암호의 유사성을 점검 확인, 주로 difok 값으로 조절하는데 새로운 암호가 이전암호와 얼마나 많은 다른 문자들을 가지고 있는가를 설정한다. 기본값은 10이거나 새로운 암호 크기의 1/2 중

작은 값이다.

새 암호가 너무 짧지 않는가 확인, 주로 minlen, dcredit, ucredit, lcredit, ocredit 으로 조절한다.

새 암호가 이전 암호를 돌려 쓰기(shift)만 한것은 아닌가 확인

새 암호가 이전에 사용되었는가를 점검, 이전 암호는 /etc/security/opasswd에 저장된다.

 

 

 

모듈인자

debug

모듈이 동작을 보여주기 위해 syslog에 정보를 남긴다. 이 옵션이 로그 파일에 패스워드 정보를

남기지 않는다.

type=LINUX

모듈의 기본 동작은 패스워드를 물어 볼때 "New UNIX password:", "Retype UNIX password:"라고 묻는데, 이 옵션을 사용하여 "UNIX"라는 말 대신 "LINUX"로 바꿀수 있다.

retry=N

새 패스워드를 물어 보는 횟수로서 기본값은 1이다. 이 옵션을 사용하면 N만큼 회수를 늘릴수 있다.

difok=N (differnent ok)

새 패스워드에서 예전 패스워드에 있지 않는 문자들을 몇자나 사용해야 하는지 나타내는 수로 기본값은 10이고, 새 패스워드에서 1/2이상의 글자가 이전과 다르다면 새 패스워드로 받아들여 진다.(다시 말해서, 이전 암호와 새로운 암호는 반 이상은 틀려야 하며, 최대 10글자 까지 틀려야 한다.)

minlen=N (minimum password length)

새 패스워드의 최소 크기에 1을 더한 크기이다. 새 패스워드에 사용된 문자열의 길이외에 각 문자 종류(숫자, 대문자, 소문자, 특수문자)를 사용한 것에 대해 각각 크레디트(credit)를 준다.

만약, minlen=12 설정이 되어 있다면, 실제적으로 최소 패스워드의 길이 12가 되어야 한다. 하지만, credit이라는 값이 부여되면 minlen의 값에서 credit만큼 최소의 길이를 줄여준다. 예를 들어, minlen의 길이가 12일때 패스워드를 gksskae01! 이라고 설정했다고 가정하면, 실제 길이는 10자이다. 그러나 패스워드는 사용가능하다. 이유는, 소문자를 사용함으로써 1크레디트, 숫자를 사용하여 1크래디트, 특수문자를 사용하여 1크레디트를 얻었으므로 3크래디트를 얻는다. 이런 경우 총 문자의 길이는 12 - 3 이므로 실제적으로 9자 이상이면 가능하다.

dcredit=N (decimal credit)

숫자가 가질수 있는 크레디트값의 최대값이다. 기본값은 1이다. 만약 패스워드에 N개 이하의 숫자를 사용했다면 사용된 숫자의 개수가 현재 정의된 minlen값을 계산하는데 크레디트값으로 적용된다.

ucredit=N (upper case credit)

대문자가 가질수 있는 크레디트값의 최대값이다. 기본값은 1이다. 만약 패스워드에 N개 이하의 대문자를 사용했다면 사용된 대문자의 개수가 현재 정의된 minlen값을 계산하는 크레디트값으로 적용된다.

lcredit=N (lower case credit)

소문자가 가질수 있는 크레디트 값의 최대값이다. 기본값은 1이다. 만약 패스워드에 N개 이하의 대문자를 사용했다면 사용된 대문자의 개수가 현재 정의된 minlen값을 계산하는 크레디트값으로 적용된다.

ocredit=N (other case credit)

특수문자가가 가질수 있는 크레디트 값을 지정한다. 기본값은 1이다.

use_authok

이 인자는 사용자에게 새 패스워드를 묻지말고 앞서 실행된 패스워드 모듈에서 받은 것을 사용하도록 모듈에게 강제한다.

 

 

 

[EX] 모듈을 사용하는 PAM 파일 찾기

[root@linux200 /lib64/security]# find /etc/pam.d -type f -exec grep -l pam_pwquality {} \;

/etc/pam.d/system-auth-ac

/etc/pam.d/password-auth-ac

 

 

# vi /etc/pam.d/system-auth-ac

#%PAM-1.0

# This file is auto-generated.

# User changes will be destroyed the next time authconfig is run.

auth required pam_env.so

auth sufficient pam_unix.so nullok try_first_pass

auth requisite pam_succeed_if.so uid >= 500 quiet

auth required pam_deny.so

 

account required pam_unix.so

account sufficient pam_succeed_if.so uid < 500 quiet

account required pam_permit.so

 

password requisite pam_cracklib.so try_first_pass retry=3

password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok

password required pam_deny.so

 

session optional pam_keyinit.so revoke

session required pam_limits.so

session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid

session required pam_unix.so

 

password requisite pam_cracklib.so try_first_pass retry=3

 

# find /etc/pam.d -type f -exec grep -l retry {} \;

try_first_pass

retry=3 : 새 암호를 물어 보는 회수가 3이다.

 

 

 

 

■ /lib/security/pam_wheel.so 모듈

# man pam_wheel

NAME

pam_wheel - Only permit root access to members of group wheel

 

SYNOPSIS

pam_wheel.so [debug] [deny] [group=name] [root_only] [trust] [use_uid]

 

DESCRIPTION

The pam_wheel PAM module is used to enforce the so-called wheel group. By

default it permits root access to the system if the applicant user is a

member of the wheel group. If no group with this name exist, the module is

using the group with the group-ID 0.

 

OPTIONS

debug

Print debug information.

 

deny

Reverse the sense of the auth operation: if the user is trying to get

UID 0 access and is a member of the wheel group (or the group of the

group option), deny access. Conversely, if the user is not in the

group, return PAM_IGNORE (unless trust was also specified, in which

case we return PAM_SUCCESS).

 

group=name

Instead of checking the wheel or GID 0 groups, use the name group to

perform the authentification.

 

trust

The pam_wheel module will return PAM_SUCCESS instead of PAM_IGNORE if

the user is a member of the wheel group (thus with a little play

stacking the modules the wheel members may be able to su to root

without being prompted for a passwd).

 

use_uid

The check for wheel membership will be done against the current uid

instead of the original one (useful when jumping with su from one

account to another for example).

 

EXAMPLES

The root account gains access by default (rootok), only wheel members can

become root (wheel) but Unix authenticate non-root applicants.

 

su auth sufficient pam_rootok.so

su auth required pam_wheel.so

su auth required pam_unix.so

 

 

모듈설명

root 권한을 얻을 수 있는 사용자를 wheel(gid=0)이라는 그룹으로 묶어서 사용하도록 지원하는 모듈이다. 다시 말해서, 이 모듈은 기본적으로 root 권한을 얻을 수 있는 자격을 사용자가 wheel 그룹에 속한 경우에만 가능하도록 한다.(우선, 이 모듈은 wheel 그룹에 존재하는지를 먼저 검사하고, 만약 없다면 group id가 0인 그룹을 wheel 그룹으로 지정한다.)

 

 

모듈인자

debug

syslog에 더 많은 정보를 제공한다.

group=그룹명

gid=0인 그룹을 검사하는 대신 인증을 위해서 '그룹명' 그룹을 검사한다. (여기서 그룹명은 그룹의 이름이지 숫자로 된 그룹의 ID가 아니다.)

trust

이 옵션을 사용하면 root 권한을 요구한 사용자가 wheel 그룹에 속한 경우 PAM_SUCCESS를 돌려주도록 한다. 즉, wheel group에 속한 사용자들은 암호를 입력하지 않고도 root 권한을 획득할 수 있게 된다. (주의해서 사용해야 한다.)

deny

모듈의 동작을 반대로 하도록 만든다. 만약 사용자가 wheel 그룹에 속한 사용자가 uid=0을 얻기 시도하면 접근을 거부한다. 이 옵션을 단독적으로는 쓸모가 없고 'group=' 옵션과 같이 사용하기 위해 만들어졌다.

use_uid

login 할 때의 이름을 이용하지 않고 현재 프로세스의 uid를 이용한다. 예를 들어 su 명령어 같은 경우와 같이 한 계정에서 다른 계정으로 뛰어 넘는 경우 유용하다.

 

 

[EX] 모듈을 사용하는 PAM 파일 찾기

# find /etc/pam.d -type f -exec grep -l pam_wheel.so {} \;

/etc/pam.d/su

 

 

# vi /etc/pam.d/su

#%PAM-1.0

auth sufficient pam_rootok.so

# Uncomment the following line to implicitly trust users in the "wheel" group.

#auth sufficient pam_wheel.so trust use_uid

# Uncomment the following line to require a user to be in the "wheel" group.

#auth required pam_wheel.so use_uid

auth include system-auth

account sufficient pam_succeed_if.so uid = 0 use_uid quiet

account include system-auth

password include system-auth

session include system-auth

session optional pam_xauth.so

 

 

 

 


 

 

 

[PAM 관련 실습]

 

 

 

[EX] PAM 파일내의 PAM 모듈의 기능을 찾는 방법

[EX] PAM 모듈을 사용하는 PAM 파일을 찾고 찾은 PAM 파일내의 다른 PAM 모듈 기능 확인하는 방법

[EX] 사용자 패스워드 길이 제한하기

[EX] su 명령어를 특정 사용자에게만 허가한다.

[EX] 특정 계정에 대해 telnet 접속을 막고, ftp 접속만 허가해 보자.

[EX] 패스워드 변경 정책

 

 

 

1. PAM 파일내의 PAM 모듈의 기능을 찾는 방법

 

PAM aware App. -> PAM Library -> PAM File -> PAM Module

/bin/su===> /lib/libpam.so.0 =====> /etc/pam.d/su ====> /lib/security/xxxxx.so

 

 

 

# cd /etc/pam.d

# ls

passwd 


# cat passwd

#%PAM-1.0

auth include system-auth

account include system-auth

password substack system-auth

-password optional pam_gnome_keyring.so use_authtok

password substack postlogin

 

 

# cat system-auth

#%PAM-1.0

# This file is auto-generated.

# User changes will be destroyed the next time authconfig is run.

auth required pam_env.so

auth required pam_faildelay.so delay=2000000

auth sufficient pam_fprintd.so

auth sufficient pam_unix.so nullok try_first_pass

auth requisite pam_succeed_if.so uid >= 1000 quiet_success

auth required pam_deny.so

 

 

account required pam_unix.so

account sufficient pam_succeed_if.so uid < 500 quiet

account required pam_permit.so

 

password requisite pam_cracklib.so try_first_pass retry=3

password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok

password required pam_deny.so

 

session optional pam_keyinit.so revoke

session required pam_limits.so

session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid

session required pam_unix.so

 

 

# man pam_env

NAME

pam_env - PAM module to set/unset environment variables

 

SYNOPSIS

pam_env.so [debug] [conffile=conf-file] [envfile=env-file]

[readenv=0|1]



 

2. PAM 모듈을 사용하는 PAM 파일을 찾고 찾은

PAM 파일내의 다른 PAM 모듈 기능 확인하는 방법

# cd /lib64/security (# cd /usr/lib64/security)

# ls *env*

pam_env.so

 

 

# find /etc/pam.d -type f -exec grep -l pam_env.so {} \;

/etc/pam.d/gdm-autologin

/etc/pam.d/gdm-launch-environment

/etc/pam.d/atd

/etc/pam.d/system-auth-ac

/etc/pam.d/password-auth-ac

/etc/pam.d/fingerprint-auth-ac

/etc/pam.d/smartcard-auth-ac


# cat /etc/pam.d/crond

#

# The PAM configuration file for the cron daemon

#

#

auth sufficient pam_env.so

auth required pam_rootok.so

auth include system-auth

account required pam_access.so

account include system-auth

session required pam_loginuid.so

session include system-auth

 

 

# man pam_env.so

-> 정보 확인

 

 

 

 

3. 사용자 패스워드 길이 제한하기

리눅스에서 패스워드 기본설정과 관련된 파일이 /etc/login.defs이다. 이 파일에서 패스워드의 길이는 최소 5자로 설정하고 있다. 이 파일에서 설정해도 되지만 PAM을 이용하여 패스워드의 길이를 설정할 수도 있다. 기본 설정 파일은 /etc/pam.d/passwd 파일이다.

 

# cat /etc/pam.d/passwd

#%PAM-1.0

auth include system-auth

account include system-auth

password include system-auth


# cat /etc/pam.d/system-auth

is file is auto-generated.

# User changes will be destroyed the next time authconfig is run.

auth required pam_env.so

auth sufficient pam_unix.so nullok try_first_pass

auth requisite pam_succeed_if.so uid >= 500 quiet

auth required pam_deny.so

 

account required pam_unix.so

account sufficient pam_succeed_if.so uid < 500 quiet

account required pam_permit.so

 

password requisite pam_cracklib.so try_first_pass retry=3

password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok

password required pam_deny.so

 

session optional pam_keyinit.so revoke

session required pam_limits.so

session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid

session required pam_unix.so



 

# vi /etc/pam.d/passwd

#%PAM-1.0

[수정전]

auth include system-auth

account include system-auth

password include system-auth

[수정후]

auth include system-auth

account include system-auth

#password include system-auth

password required pam_cracklib.so retry=3 type=LINUX(배제 가능)

password sufficient pam_unix.so md5 shadow nullok use_authok

password required pam_deny.so

 

-> /etc/pam.d/system-auth 파일의 설정을 따르지 않고 새로운 모듈로 설정하였다.

pam_cracklib.so retry=3 minlen=12 type=LINUX 해석

- retry=3 : 3번까지 재시도 할 수 있도록 한다. 3번이 지나면 fail 메세지를 받는다.

- minlen=12 : 패스워드의 최소 길이를 나타낸다. 13글자 이상의 패스워드를 사용해야 한다.

- type=LINUX : 모듈의 기본 동작은 패스워드를 물어 볼 때 "New UNIX password", Retype UNIX

password" 라고 묻는다. 이 옵션을 사용하면 UNIX 대신에 LINUX로 변경할 수 있

다.

 

# telnet localhost

user02 사용자로 로그인

 

$ passwd

Changing password for user user02.

Changing password for user02

(current) UNIX password: (user02)

New LINUX password: (abcdefg1234.)

Retype new LINUX password: (abcdefg1234.)

Enter new UNIX password: (abcdefg1234.)

Retype new UNIX password: (abcdefg1234.)

passwd: all authentication tokens updated successfully.

 

-> 현재 암호를 물어 보고 맞추면, 새로운 암호를 3번 물어 본다.(retry=3)

-> 암호 재입력(retry)를 3번하라고 정의해서 그렇다.

 

$ exit

# passwd user02

Changing password for user user02.

New LINUX password: (user02)

BAD PASSWORD: it is based on a dictionary word

Retype new LINUX password: (user02)

Enter new UNIX password: (user02)

Retype new UNIX password: (user02)

passwd: all authentication tokens updated successfully.



 

 

4. su 명령어를 특정 사용자에게만 허가한다.

특정사용자만 특정한 그룹(보통 wheel)에 속하도록 하여 그 그룹에 속한 사요자만 특정한 권한을 가도록 하기 위해 pam_wheel.so라는 모듈을 제공한다. 또한 리눅스에서는 기본적으로 wheel 그룹이 생성되어 있다.

 

# usermod -G wheel user03

# grep user03 /etc/group (# id user03)

wheel:x:10:root,user03

user03:x:502:


# vi /etc/pamd.d/su

[수정전]

#%PAM-1.0

auth sufficient pam_rootok.so

#auth required /lib/security/pam_wheel.so debug group=wheel

# Uncomment the following line to implicitly trust users in the "wheel" group.

#auth sufficient pam_wheel.so trust use_uid

# Uncomment the following line to require a user to be in the "wheel" group.

#auth required pam_wheel.so use_uid

auth include system-auth

account sufficient pam_succeed_if.so uid = 0 use_uid quiet

account include system-auth

password include system-auth

session include system-auth

session optional pam_xauth.so

[수정후]

#%PAM-1.0

auth sufficient pam_rootok.so

auth required /lib/security/pam_wheel.so debug group=wheel

# Uncomment the following line to implicitly trust users in the "wheel" group.

#auth sufficient pam_wheel.so trust use_uid

# Uncomment the following line to require a user to be in the "wheel" group.

#auth required pam_wheel.so use_uid

auth include system-auth

account sufficient pam_succeed_if.so uid = 0 use_uid quiet

account include system-auth

password include system-auth

session include system-auth

session optional pam_xauth.so

 

 

# telnet localhost

user03 사용자로 로그인

 

$ su - root

-> root 사용자 암호 입력

# exit

$ exit

 

[참고] 필요하면 명령어 수행

# useradd user04

# echo user04 | passwd --stdin user04

 

# telnet localhost

user04 사용자로 로그인

 

$ su - root

Password:

su: incorrect password



 

 

5. /etc/ssh/sshnusers 파일에 등록된 사용자만 ssh 로그인이 허용되지 않도록 해 보자.

/etc/pam.d/sshd 파일의 내용을 편집하여 /etc/ssh/sshnusers 파일에 등록된 사용자만 ssh 서버에 접속할 수 없도록 설정해 보자.

그리고 /etc/ssh/sshusers 파일에 등록되지 않은 사용자는 허용이 되는것도 확인하자.

 

# vi /etc/pam.d/sshd

#%PAM-1.0

auth required pam_sepermit.so (selinux를 먼저 읽어들인 후 작업 되도록 해야 한다)

auth required pam_listfile.so item=user sense=deny file=/etc/ssh/sshusers onerr=succeed

auth include system-auth

account required pam_nologin.so

account include system-auth

password include system-auth

session optional pam_keyinit.so force revoke

session include system-auth

session required pam_loginuid.so

 

 

# vi /etc/ssh/sshusers

user01


자율적으로 실습을 진행한다.

 

# ssh user01@192.168.20.200 (접속 안됨)

# ssh user02@192.168.20.200 (접속됨)

 

 

 

 

6. /etc/ssh/sshusers 파일에 등록된 사용자만 ssh 로그인을 허용하도록 해 보자.

/etc/pam.d/sshd 파일의 내용을 편집하여 /etc/ssh/sshusers 파일에 등록된 사용자만 ssh 서버에 접속할 수 있도록 설정해 보자.

그리고 /etc/ssh/sshusers 파일에 등록되지 않은 사용자는 ssh 서버에 접속할 수 없다는 것도 확인하자.

 

# vi /etc/pam.d/sshd

#%PAM-1.0

auth required pam_sepermit.so (selinux를 먼저 읽어 드린 후 작업되도록 해야 한다)

 

auth required pam_listfile.so item=user sense=allow file=/etc/ssh/sshusers onerr=fail

auth include system-auth

account required pam_nologin.so

account include system-auth

password include system-auth

session optional pam_keyinit.so force revoke

session include system-auth

session required pam_loginuid.so

 

 

# cat /etc/ssh/sshusers

user01

 

자율적으로 실습을 진행한다.

 

(복원)

/etc/pam.d/sshd 파일 원래대로 복원한다.

[EX] 패스워드 변경 정책

 

!!!! 로그인시 최소 패스워드를 12자 이상 설정 !!!!

 

(ㄱ) /etc/login.defs(PASS_MIN_LEN)

(ㄴ) PAM File(system-auth-ac(pam_cracklib(minlen)))

 

 

# cat /etc/pam.d/passwd

#%PAM-1.0

auth include system-auth

account include system-auth

password include system-auth

 

# ls -l /etc/pam.d/system-auth

lrwxrwxrwx 1 root root 14 Apr 27 19:17 system-auth -> system-auth-ac(원본파일)

 

 

수정에 앞서!

7버전 이상부터는 이걸 직접 바꾸면 안되고

 

# cd /etc/security/pwquality.conf

들어가서 minlen을 12로 수정!

 

 

# vi /etc/pam.d/system-auth-ac (원본파일)

[수정전] 7.0 이하버전만!

password requisite pam_cracklib.so try_first_pass retry=3

[수정후]

password requisite pam_cracklib.so try_first_pass retry=3 minlen=12

 

패스워드에서 사용가능한 문자: 숫자, 영어 대/소 문자, 특수문자

크레디트값: 숫자1, 영어1, 특수기호1

 

 

minlen=12

 

 

# man pam_cracklib

-> 정보 확인

 

■ pam_cracklib.so 인자 값에 대해서

debug : syslog 파일에 로그 기록

type=LINUX

(예) # passwd user01

NEW UNIX password : --> NEW LINUX password :

retry=N : 패스워드 입력 실패 시 재시도 회수 지정

difok=N : 기존 패스워드와 비교, 기본값10(50%)

minlen=N : 크레디트를 더한 패스워드 최소길이

dcredit=N : 숫자에 주어지는 크레디트값, 기본값: 1

ucredit=N : 영어대문자에 주어지는 크레디트값

lcredit=N : 영어소문자에 주어지는 크레디트값

ocredit=N : 숫자, 영어 대/소문자를 제외한 기타 문자

use_authok : 기존 패스워드를 다시 사용

MD5 값을 적용

 

 

기본값에 대한 테스트

 

입력가능한 패스워드 최소 길이는?

$ passwd

글자수

입력 암호

 

5

apple

BAD PASSWORD: it is too short

6

apples

BAD PASSWORD: it is based on a dictionary word

111111

 

BAD PASSWORD: it does not contain enough DIFFERENT characters

qwer123

 

BAD PASSWORD: it is based on a dictionary word

 

입력 암호

 

12345

BAD PASSWORD: it is too short

123456

BAD PASSWORD: it is too simplistic/systematic

111111

BAD PASSWORD: it does not contain enough DIFFERENT characters

qwer123

BAD PASSWORD: it is based on a dictionary word

 

 

 

 

(예제)

password required pam_cracklib.so difok=3 minlen=15 dcredit=2 ocredit=2

password required pam_pwdb.so use_authok nullok md5

 

■ 패스워드 변경 규칙을 적용에 대해서(다음과 같은 적용 규칙을 설정하라)

패스워드의 최소길이 8자(pam_cracklib.so minlen=(8 + 4))

소문자 최소 1자(pam_cracklib.so lcredit=-1)

대문자 최소 1자(pam_cracklib.so ucredit=-1)

숫자 최소 1자(pam_cracklib.so dcredit=-1)

문자와 숫자이외의 문자 최소 1자(pam_cracklib.so ocredit=-1)

 

# vi /etc/pam.d/system-auth

#%PAM-1.0

# This file is auto-generated.

# User changes will be destroyed the next time authconfig is run.

auth required pam_env.so

auth required pam_tally.so per_user

auth sufficient pam_unix.so nullok try_first_pass

auth requisite pam_succeed_if.so uid >= 500 quiet

auth required pam_deny.so

 

account required pam_unix.so

account sufficient pam_succeed_if.so uid < 500 quiet

account required pam_permit.so

 

password requisite pam_cracklib.so try_first_pass retry=3 minlen=12 ucredit=-1 dcredit=-1 ocredit=-1 lcredit=-1

password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok

password required pam_deny.so

 

session optional pam_keyinit.so revoke

session required pam_limits.so

session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid

session required pam_unix.so

 

"auth required pam_tally.so per_user"

-> faillog 설정에 따름

"passwd requisite pam_cracklib.so try_first_pass retry=3 minlen=8 ucredit=-1 dcredit=-1 ocredit=-1 lcredit=-1

- retry=3 : 패스워드 입력 실패 재시도 회수는 3

- minlen=8 : 크레디트를 더한 패스워드 최소길이

- ucredit=-1 : 영어대문자에 주어지는 크레디트 값

- dcredit=-1 : 숫자에에 주어지는 크레디트값, 기본값은 1

- ocredit=-1 : 숫자,영어대/소문자를 제외한 기타 문자

- lcredit=-1 : 영어 소문자에 주어지는 크레디트 값

(각 항목에서 -1값을 주면 반드시 해당하는 문자를 포함시켜야 함. 즉 dcredit=-1이라면 패스워드에 숫자가 반드시 포함되어야 함.)

 

 

 

 

[참고 사이트]

 

http://coffeenix.net/doc/Translations/html/PAM_admin-KLDP/index.html

https://wiki.kldp.org/Translations/html/PAM_admin-KLDP/x394.html

http://www.kernel.org/pub/linux/libs/pam/pre/doc/rfc86.0.txt.gz

 

 

 


 

 

[정리]

 

 

CentOS 7.0 이상에서 암호 설정 변경

(CLI) authconfig CMD

(TUI) authconfig-tui

(GUI) authconfig-gtk

 

 

# yum –y install authconfig-gtk

# authconfig-gtk &

‘암호 옵션’ 탭

 

이 툴에서 설정한 값은

cat /etc/security/pwquality.conf 파일에 들어가서 확인 가능.

 

 

내용이 추가 + 변경된 것을 볼 수 있다.

 

 

* 파일 직접 편집은 권장 사항이 아님!

 

 

 

[CLI 사용 예]

# authconfig --help | grep passmin

--passminlen=<number>

--passminclass=<number>

 

# authconfig --passminlen=12 --passminclass=4 --update

변경사항 확인은

# cat /etc/security/pwquality.conf

 

728x90

+ Recent posts