Añadir usuario linux a Active Directory

­

Improvisa :: Informática :: Añadir usuario Linux a Active DirectoryEn esta pequeña receta os enseñaremos y además me recordará cada vez que tenga que hacerlo, a añadir a un usuario con una máquina GNU/Linux a inciar sesión en un Active Directory o PDC, para que de esa forma una vez que iniciamos sesión en nuestro sistema, automáticamente el sistema inciará sesión también en el contraldor de dominio Active Directory.

Para ello utlizaremos el conjunto de aplicaciones Samba, autenticación Kerberos, Winbind y algún que otro paquete más.

Sin más os dejo con la receta:

Para comenzar contaros que yo como siempre utilizo Debian esta receta será para la última versión estable o también llamada Lenny.

Partiremos de un ssitema recien instalado el cual necesitamos agregar a un dominio ya creado  con una cuenta de usuario ya creada. Esta cuenta creada en el PDC debe ser la misma que la que utilizaremos para entrar en nuestro Debian.

Una vez instalado el sistema con su sistema gráfico y todo, pasaremos modificar la configuración para que cada vez que etremos a nuestro sistema nuevo, automaticamente inicie la sesión en el PDC a la vez que entramos en nuestro sistema. Para ello utilizaremos nuestr gestos de inicio de sesión, en mi caso GDM.

Para ello, como he dicho antes supondremos que ya tenemos la cuenta del cliente creada, en el ejemplo tomaremos como dominio de prueba el nombre DOMINIO.LOCAL, con la ip 192.168.1.1, el nombre del controlador de dominio sera en nuestro ejemplo pdc.edages.local y como usuario juanmi

Comencemos instalando unos cuantos paquetes:

improvisa:~# apt-get install samba smbclient winbind krb5-user krb5-config ntpdate

Una vez realizado comenzaremos a modificar la configuración de samba, para ello haremos una copia del archivo original y crearemos uno nuevo:

improvisa:~# mv /etc/samba/smb.conf /etc/samba/smb.conf.ORIGINAL

Editaremos el nuevo archivo:

improvisa:~# vi /etc/samba/smb.conf

Y pondremos el siguiente contenido, cambiandolo según sea cada caso, respetad las MAYUSCULAS.

[global]
workgroup = DOMINIO
realm = DOMINIO.LOCAL
security = ADS
password server = 192.168.1.1
log level = 1
syslog = 0
printcap name = cups
domain master = No
wins server = 192.168.1.1
idmap uid = 10000-29999
idmap gid = 10000-29999
winbind separator =
winbind use default domain = Yes
winbind enum users = Yes
winbind enum groups = Yes
winbind use default domain = Yes
netbios name = juanmi
template homedir = /home/%D/%U
template shell = /bin/bash
client use spnego = yes
domain master = no
server string = Juanmi
encrypt passwords = true
dos charset = 850
unix charset = iso-8859-15

[homes]
comment = Home Directories
valid users = %S
browseable = No
read only = No
inherit acls = Yes

[profiles]
comment = Network Profiles Service
path = %H
read only = No
store dos attributes = Yes
create mask = 0600
directory mask = 0700

[printers]
comment = All Printers
path = /var/spool/samba
create mask = 0700
printable = Yes
browseable = Yes

[print$]
comment = Printer Drivers
path = /var/lib/samba/printers

[Comparto]
comment = Comparto en Juanmi
path = /home/juanmi/Desktop/Comparto
read only = No
inherit acls = Yes
public = no
browseable = yes
create mask= 664
force create mode = 664
directory mask = 775
force directory mode = 775

[Musica]
comment = Musica
path = /home/juanmi/Desktop/Musica
read only = No
inherit acls = Yes

Crearemos el directorio para alojar las home de cada usuario del dominio:

improvisa:/etc/pam.d# mkdir /home/DOMINIO

Continuaremos ahora configurando más archivos, demosle a /etc/krb5.conf

improvisa:~# vi /etc/krb5.conf

y pongamos el siguiente contenido, cambiandolo de nuevo con vuestras opciones:

[libdefaults]
krb4_config = /etc/krb.conf
krb4_realms = /etc/krb.realms
kdc_timesync = 1
ccache_type = 4
forwardable = true
proxiable = true
v4_instance_resolve = false
v4_name_convert = {
host = {
rcmd = host
ftp = ftp
}
plain = {
something = something-else
}
}
fcc-mit-ticketflags = true
clockskew = 300

# The following krb5.conf variables are only for MIT Kerberos.

# The following encryption type specification will be used by MIT Kerberos
# if uncommented.  In general, the defaults in the MIT Kerberos code are
# correct and overriding these specifications only serves to disable new
# encryption types as they are added, creating interoperability problems.

#       default_tgs_enctypes = aes256-cts arcfour-hmac-md5 des3-hmac-sha1 des-cbc-crc des-cbc-md5
#       default_tkt_enctypes = aes256-cts arcfour-hmac-md5 des3-hmac-sha1 des-cbc-crc des-cbc-md5
#       permitted_enctypes = aes256-cts arcfour-hmac-md5 des3-hmac-sha1 des-cbc-crc des-cbc-md5

# The following libdefaults parameters are only for Heimdal Kerberos.

[realms]
DOMINIO.LOCAL = {
kdc = 192.168.1.1
default_domain = dominio.local
admin_server = 192.168.1.1
        }
dominio.local = {
kdc =
192.168.1.1
                default_domain = dominio.local
admin_server = 1
92.168.1.1
        }
dominio = {
kdc =
192.168.1.1
                default_domain = dominio
admin_server =
192.168.1.1
        }
[logging]
kdc = FILE:/var/log/krb5/krb5kdc.log
admin_server = FILE:/var/log/krb5/kadmind.log
default = SYSLOG:NOTICE:DAEMON

[domain_realm]
.dominio = dominio
.dominio.local = DOMINIO.LOCAL

[appdefaults]
pam = {
ticket_lifetime = 1d
renew_lifetime = 1d
forwardable = true
proxiable = false
retain_after_close = false
minimum_uid = 0
try_first_pass = true
}
Editaremos ahora todos los archivos para que cuando iniciemos utilicen los datos introducidos para que inicie la sesión contra el Active Directory:

improvisa:~# cd /etc/pam.d/

improvisa:/etc/pam.d# ­vi common-account

Y lo dejaremos así:

 #
# /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 sufficient      pam_winbind.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
# 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

Ahora

improvisa:/etc/pam.d# vi common-auth

Y lo dejaremos así:

#
# /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    sufficient      pam_winbind.so
auth    [success=1 default=ignore]      pam_unix.so nullok_secure try_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

Ahora

improvisa:/etc/pam.d# vi common-session

Y lo dejaremos así:

#
# /etc/pam.d/common-session – session-related modules common to all services
#
# This file is included from other service-specific PAM config files,
# and should contain a list of modules that define tasks to be performed
# at the start and end of sessions of *any* kind (both interactive and
# non-interactive).
#
# 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)
session [default=1]                     pam_permit.so
# here’s the fallback if no module succeeds
session 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
session required                        pam_permit.so
# and here are more per-package modules (the «Additional» block)
session sufficient      pam_winbind.so
session required        pam_unix.so
session optional                        pam_ck_connector.so nox11
# end of pam-auth-update config

Ahora

improvisa:/etc/pam.d# vi common-password

Y lo dejaremos así:

#
# /etc/pam.d/common-password – password-related modules common to all services
#
# This file is included from other service-specific PAM config files,
# and should contain a list of modules that define the services to be
# used to change user passwords.  The default is pam_unix.

# Explanation of pam_unix options:
#
# The «md5» option enables MD5 passwords.  Without this option, the
# default is Unix crypt.
#
# The «obscure» option replaces the old `OBSCURE_CHECKS_ENAB’ option in
# login.defs.
#
# See the pam_unix manpage for other options.

# 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)
password        sufficient      pam_winbind.so
password        [success=1 default=ignore]      pam_unix.so obscure use_authtok try_first_pass md5
# here’s the fallback if no module succeeds
password        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
password        required                        pam_permit.so
# and here are more per-package modules (the «Additional» block)
password        optional        pam_gnome_keyring.so
# end of pam-auth-update config

Y por último  editaremos la configuación de nuestro gestor de sesiones, en mi caso GDM, como dije más arriba:

improvisa:/etc/pam.d# vi gdm

Y lo dejaremos así:

 #%PAM-1.0
auth required /lib/security/pam_securetty.so
auth sufficient /lib/security/pam_winbind.so
auth sufficient /lib/security/pam_unix.so use_first_pass envfile=/etc/default/locale
auth required /lib/security/pam_nologin.so
account sufficient /lib/security/pam_winbind.so
session required /lib/security/pam_mkhomedir.so skel=/etc/skel
umask=0022
auth requisite pam_nologin.so
auth    required        pam_env.so readenv=1
auth    required   ­;     pam_env.so readenv=1 envfile=/etc/default/locale
;@include common-auth
;@include common-account
session required pam_limits.so
;@include common-session
session optional /lib/security/pam_console.so
;@include common-password

Ahora debemos editar el archivo  /etc/nsswitch.conf para decirle que utilice tambien winbind:

improvisa:/etc/pam.d# vi /etc/nsswitch.conf

y lo dejaremos como aparece aquí:

#/etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference’ and `info’ packages installed, try:
# `info libc «Name Service Switch»‘ for information about this file.

passwd:         files winbind
group:          files winbind
shadow:         files winbind

hosts:          files dns winbind
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

Perfecto ya tenemos todo configurado, ahora ajustaremos la hora del sistema para que no nos falle con el servidor, el cual asumimos que lo tenemos en hora:

improvisa:/etc/pam.d# ntpdate hora.rediris.es

Crearemos los tickets Kerberos con el siguiente comando, necesitaremos el password del administrador del dominio:

improvisa:/etc/pam.d# kinit administrador@DOMINIO.LOCAL

Solo si os da problemas al recibir los tickets Kerberos volved a intentarlo con el nombre del dominio en minusculas:

improvisa:/etc/pam.d# kinit administrador@dominio.local

Reiniciemos Samba y Windbind y comprobemos la configuración:

improvisa:/etc/pam.d# /etc/init.d/samba restart

improvisa:/etc/pam.d# /etc/init.d/winbind restart

improvisa:/etc/pam.d# testparm

Uniremos la máquina al dominio con el siguiente comando:

improvisa:/etc/pam.d# net ads join -S 192.168.1.1  -U administrador

Using short domain name — DOMINIO
Joined ‘IMPROVISA’ to realm ‘DOMINIO.LOCAL’

Si os diese algún problema probad con el nombre del servidor Active Directory, en nuestro ejemplo PDC:

improvisa:/etc/pam.d# net ads join -S pdc.dominio.local  -U administrador

Ahora solo nos queda comprobar que hemos hecho todo bien:

improvisa:/etc/pam.d# net rpc testjoin

Join to ‘DOMINIO’ is OK

improvisa:/etc/pam.d# net ads info­

LDAP server: 192.168.1.1
LDAP server name: pdc.dominio.local
Realm: DOMINIO.LOCAL
Bind Path: dc=DOMINIO,dc=LOCAL
LDAP port: 389
Server time: jue, 2 jul 2009 14:36:04 CEST
KDC server: 192.168.1.1
Server time offset: 0

improvisa:/etc/pam.d# net rpc info -U juanmi

Enter juanmi’s password:
Domain Name: DOMINIO
Domain SID: S-1-5-21-224523388-1220989662-682023330
Sequence number: 7529
Num users: 169
Num domain groups: 0
Num local groups: 12

improvisa:/etc/pam.d# wbinfo -u

Nos dará los usuarios del dominio

improvisa:/etc/pam.d# wbinfo -g

Nos dará los grupos del dominio

improvisa:/etc/pam.d# getent passwd

Nos dará más información de los usuarios del dominio

improvisa:/etc/pam.d# getent group

Nos dará más información de los grupos del dominio

Ahora solo nos queda reiniciar el equipo y comprobar que una vez metido el usuario y la contraseña en GDM podemos volver a lanzar los comandos de comprobación de arriba:

 

improvisa:/etc/pam.d# net rpc testjoin

improvisa:/etc/pam.d# net ads info

improvisa:/etc/pam.d# net rpc info -U juanmi

improvisa:/etc/pam.d# wbinfo -u

improvisa:/etc/pam.d# wbinfo -g

improvisa:/etc/pam.d# getent passwd

improvisa:/etc/pam.d# getent group

Ya podrán entrar en nuestro equipo los usuarios del dominio si que se les pida password.

Saludos y espero que os haya valido.

Print Friendly, PDF & Email
Comentarios

    Warning: Use of undefined constant type - assumed 'type' (this will throw an Error in a future version of PHP) in /home/improvisa_com/web/improvisa.com/public_html/wp-content/themes/grassland/comments.php on line 38
  • krlos dice:

    Hola muy bueno el tema y me funciono perfectamente sin embargo estoy teniendo un problema y es que de vez en vez Ubuntu de pronto se sale del PDC y tengo que volver a unirle nuevamente para que los usuarios puedan acceder a sus  cuentas, he revisado un poco san google y hasta ahora nada estoy viendo la posibilidad de hacer un sript  para que una la pc cada vez que inicie pero estoy aprendiendo ahora si me pudieras dar alguna idea.