Назад | Перейти на главную страницу

Аутентификация PAM / LDAP в Ubuntu 10.04

Я не могу осмыслить новый синтаксис конфигурации pam.d, используемый в Ubuntu 10.04. Как настроить PAM, чтобы он позволял пользователям, хранящимся в моей базе данных LDAP, входить в систему.

Я уже настроил nscd, поэтому id <user> или getent passwd уже перечисляют моих пользователей LDAP, но PAM не работает, будь то обычный вход в оболочку или su.

Обновление 17 июня 2010 г. 18:45

LDAP уже работает. Я могу просмотреть все учетные записи, выполнив getent passwd, но моя конфигурация PAM все еще не работает.

В листинге ниже показан мой /etc/pam.d/login

#
# The PAM configuration file for the Shadow `login' service
#

# Enforce a minimal delay in case of failure (in microseconds).
# (Replaces the `FAIL_DELAY' setting from login.defs)
# Note that other modules may require another minimal delay. (for example,
# to disable any delay, you should add the nodelay option to pam_unix)
auth       optional   pam_faildelay.so  delay=3000000

# Outputs an issue file prior to each login prompt (Replaces the
# ISSUE_FILE option from login.defs). Uncomment for use
# auth       required   pam_issue.so issue=/etc/issue

# Disallows root logins except on tty's listed in /etc/securetty
# (Replaces the `CONSOLE' setting from login.defs)
# Note that it is included as a "required" module. root will be
# prompted for a password on insecure ttys.
# If you change it to a "requisite" module, make sure this does not leak
# user name information.
auth       required  pam_securetty.so

# Disallows other than root logins when /etc/nologin exists
# (Replaces the `NOLOGINS_FILE' option from login.defs)
auth       requisite  pam_nologin.so

# SELinux needs to be the first session rule. This ensures that any 
# lingering context has been cleared. Without out this it is possible 
# that a module could execute code in the wrong domain.
# When the module is present, "required" would be sufficient (When SELinux
# is disabled, this returns success.)
session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so close

# This module parses environment configuration file(s)
# and also allows you to use an extended config
# file /etc/security/pam_env.conf.
# 
# parsing /etc/environment needs "readenv=1"
session       required   pam_env.so readenv=1
# locale variables are also kept into /etc/default/locale in etch
# reading this file *in addition to /etc/environment* does not hurt
session       required   pam_env.so readenv=1 envfile=/etc/default/locale

# Standard Un*x authentication.
@include common-auth

# This allows certain extra groups to be granted to a user
# based on things like time of day, tty, service, and user.
# Please edit /etc/security/group.conf to fit your needs
# (Replaces the `CONSOLE_GROUPS' option in login.defs)
auth       optional   pam_group.so

# Uncomment and edit /etc/security/time.conf if you need to set
# time restrainst on logins.
# (Replaces the `PORTTIME_CHECKS_ENAB' option from login.defs
# as well as /etc/porttime)
# account    requisite  pam_time.so

# Uncomment and edit /etc/security/access.conf if you need to
# set access limits.
# (Replaces /etc/login.access file)
# account  required       pam_access.so

# Sets up user limits according to /etc/security/limits.conf
# (Replaces the use of /etc/limits in old login)
session    required   pam_limits.so

# Prints the last login info upon succesful login
# (Replaces the `LASTLOG_ENAB' option from login.defs)
session    optional   pam_lastlog.so

# Prints the motd upon succesful login
# (Replaces the `MOTD_FILE' option in login.defs)
session    optional   pam_motd.so

# Prints the status of the user's mailbox upon succesful login
# (Replaces the `MAIL_CHECK_ENAB' option from login.defs). 
#
# This also defines the MAIL environment variable
# However, userdel also needs MAIL_DIR and MAIL_FILE variables
# in /etc/login.defs to make sure that removing a user 
# also removes the user's mail spool file.
# See comments in /etc/login.defs
session    optional   pam_mail.so standard

# Standard Un*x account and session
@include common-account
@include common-session
@include common-password

# SELinux needs to intervene at login time to ensure that the process
# starts in the proper default security context. Only sessions which are
# intended to run in the user's context should be run after this.
session [success=ok ignore=ignore module_unknown=ignore default=bad] pam_selinux.so open
# When the module is present, "required" would be sufficient (When SELinux
# is disabled, this returns success.)

В листинге ниже показан мой /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=2 default=ignore]  pam_unix.so nullok_secure
auth    [success=1 default=ignore]  pam_ldap.so use_first_pass
# 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)
# end of pam-auth-update config
  • Во-первых, вам нужно открыть ваш любимый менеджер пакетов и установить libpam-ldap.
    • Как только пакеты начнут распаковываться, вам зададут несколько вопросов о:
      . IP-адрес / имя хоста LDAP-сервера
      . База поиска вашего LDAP-домена и т. Д.
    • Теперь вам нужно настроить PAM, чтобы он использовал LDAP для аутентификации:
      sudo vi /etc/pam.d/login
    • вам нужно добавить одну строку над существующей строкой:

авторизация достаточна pam_ldap.so
требуется авторизация pam_unix.so try_first_pass

Или изменил файл common-auth

Восстановите ваши pam-файлы до исходных версий. Установите пакет libnss-ldap, который интегрирует доступ ldap в pam. Вы также можете установить nscd.

Настройте свой сервер в /etc/ldap.conf.

Отредактируйте /etc/nsswitch.conf, добавив ldap в конец строк для группы passwd и тени.

passwd:         compat ldap
group:          compat ldap
shadow:         compat ldap 

Проверьте, работает ли sudo getent shadow для записей ldap. Убедитесь, что вы можете получить аутентифицированное соединение с помощью ldap-search из ldap-utils, используя данные соединения /etc/ldap.conf.

В зависимости от вашей конфигурации вам также нужно будет настроить значения ssl в /etc/ldap.conf.