# How do get SSH login to work with authentication through OpenLDAP?



## olav (Dec 15, 2010)

I've created two jails(ldap.home.com and sshpam.home.com), one is with the OpenLDAP service and the other is with SSH and PAM.

I've created some openldap records which I believe are okey.
This is the output of the openldap records.

```
sshpam# ldapsearch -Z -h ldap.home.com
ldap_start_tls: Connect error (-11)
        additional info: TLS: unable to get CN from peer certificate
# extended LDIF
#
# LDAPv3
# base <dc=home,dc=com> (default) with scope subtree
# filter: (objectclass=*)
# requesting: ALL
#

# home.com
dn: dc=home,dc=com
dc: home
objectClass: dcObject
objectClass: organizationalUnit
ou: Home Dot Com

# people, home.com
dn: ou=people,dc=home,dc=com
ou: people
objectClass: organizationalUnit

# Olav Gjerde, people, home.com
dn: cn=Olav Gjerde,ou=people,dc=home,dc=com
cn: Olav Gjerde
sn: Gjerde
mail: olav@home.com
telephoneNumber: 91899959
objectClass: inetOrgPerson
objectClass: posixAccount
objectClass: shadowAccount
uid: olav
uidNumber: 1200
gidNumber: 1200
userPassword:: cGFz33dcEmQ=
loginShell: /bin/csh
homeDirectory: /home/olav

# search result
search: 3
result: 0 Success

# numResponses: 4
# numEntries: 3
```
OpenLDAP seems to work fine over the network. However the handbook is very sparse about details when it comes to setting up PAM with SSH through LDAP.

This is my /etc/pam.d/sshd

```
#
# $FreeBSD: src/etc/pam.d/sshd,v 1.16.10.1.4.1 2010/06/14 02:09:06 kensmith Exp $
#
# PAM configuration for the "sshd" service
#

# auth
auth            sufficient      pam_opie.so             no_warn no_fake_prompts
auth            requisite       pam_opieaccess.so       no_warn allow_local
#auth           sufficient      pam_krb5.so             no_warn try_first_pass
#auth           sufficient      pam_ssh.so              no_warn try_first_pass
auth            required        pam_unix.so             no_warn try_first_pass

# account
account         required        pam_nologin.so
#account        required        pam_krb5.so
account         required        pam_login_access.so
account         required        pam_unix.so

# session
#session        optional        pam_ssh.so
session         required        pam_permit.so

# password
#password       sufficient      pam_krb5.so             no_warn try_first_pass
password        required        pam_unix.so             no_warn try_first_pass

# ldap
auth            sufficient      /usr/local/lib/pam_ldap.so      no_warn
session         required        /usr/local/lib/pam_mkhomedir.so no_warn
```

This is my /etc/ssh/sshd_config

```
#       $OpenBSD: sshd_config,v 1.81 2009/10/08 14:03:41 markus Exp $
#       $FreeBSD: src/crypto/openssh/sshd_config,v 1.49.2.2.2.1 2010/06/14 02:09:06 kensmith Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

# Note that some of FreeBSD's defaults differ from OpenBSD's, and
# FreeBSD has a few additional options.

#VersionAddendum FreeBSD-20100308

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

# The default requires explicit activation of protocol 1
#Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile     .ssh/authorized_keys

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# Change to yes to enable built-in password authentication.
#PasswordAuthentication no
#PermitEmptyPasswords no

# Change to no to disable PAM authentication
ChallengeResponseAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# Set this to 'no' to disable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will 
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem       sftp    /usr/libexec/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       ForceCommand cvs server
```

When I try to login now I get this:

```
ssh olav@192.168.1.200
Password:
LDAP Password:
```
But I can't login with the user olav. Currently he only exists in openldap. He doesn't exist in the /etc/passwd file.

If I try to login with root I get the same output, and I can login as root exists as a user. But why do it ask for the LDAP password when its only the regular password ssh for authentication? For example the regular password needs the correct password. LDAP Password can be anything as long the regular password is correct.

/var/log/messages tell me this when I try to login:

```
Dec 15 14:27:42 zbtankX sshd[24841]: pam_ldap: ldap_starttls_s: Connect error
Dec 15 14:27:42 zbtankX sshd[24836]: error: PAM: authentication error for illegal user olav from 192.168.1.113
```


/var/log/auth.log

```
Dec 15 14:52:17 zbtankX sshd[25157]: pam_ldap: ldap_starttls_s: Connect error
Dec 15 14:52:17 zbtankX sshd[25155]: error: PAM: authentication error for illegal user olav from 192.168.1.113
Dec 15 14:52:17 zbtankX sshd[25155]: Failed keyboard-interactive/pam for invalid user olav from 192.168.1.113 port 39947 ssh2
```

What have I done wrong/misunderstood?


----------



## SirDice (Dec 15, 2010)

This might help: LDAP Authentication


----------



## olav (Dec 15, 2010)

Actually I found the problem here: hector has been trying hard to get it to work and described very well the process he did to get it to work.
http://forums.freebsd.org/showthread.php?t=15580

In my case it was the /etc/pam.d/sshd file which I changed to this:

```
# $FreeBSD: src/etc/pam.d/sshd,v 1.16.10.1.4.1 2010/06/14 02:09:06 kensmith Exp $
#
# PAM configuration for the "sshd" service
#

# auth
auth            sufficient      pam_opie.so             no_warn no_fake_prompts
auth            requisite       pam_opieaccess.so       no_warn allow_local
#auth           sufficient      pam_krb5.so             no_warn try_first_pass
#auth           sufficient      pam_ssh.so              no_warn try_first_pass
auth            sufficient      /usr/local/lib/pam_ldap.so      no_warn
auth            required        pam_unix.so             no_warn try_first_pass

# account
account         required        pam_nologin.so
#account        required        pam_krb5.so
account         required        pam_login_access.so
account         sufficient      /usr/local/lib/pam_ldap.so      no_warn ignore_authinfo_unavail ignore_unknown
account         required        pam_unix.so

# session
#session        optional        pam_ssh.so
session         required        pam_permit.so
session         required        /usr/local/lib/pam_mkhomedir.so no_warn

# password
#password       sufficient      pam_krb5.so             no_warn try_first_pass
password        required        pam_unix.so             no_warn try_first_pass
```

I've not yet figured out how to get pam_mkhomedir to work, but I will hopefully figure that out tomorrow


----------

