This is part of a guide to setting up an Ubuntu server for a small/medium business. The server will provide DHCP, DNS, LDAP, Kerberos and NFS services such that users can login to any machine on the network and all their files and settings will be the same across the entire network.
Now you have OpenLDAP up and running, it’s time to learn how to manage your users and groups.
Management Scripts Configuration
Firstly, we’re going to install some scripts to aid with basic management tasks:
sudo apt-get install ldapscripts
Now we need to edit the config file /etc/ldapscripts/ldapscripts.conf uncommenting and changing the following to match your environment:
# Copyright (C) 2005 Ganal LAPLANCHE - Linagora # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, # USA. # Note for Debian users: # On Debian system ldapscripts will try to parse and use some system config. # Look on commented variables and description lines started with DEBIAN. # But you could override it's values here. # LDAP Configuration # DEBIAN: values from /etc/pam_ldap.conf are used. SERVER="ldap://localhost" BINDDN="cn=admin,dc=danbishop,dc=org" # The following file contains the raw password of the binddn # Create it with something like : echo -n 'secret' > $BINDPWDFILE # WARNING !!!! Be careful not to make this file world-readable # DEBIAN: /etc/pam_ldap.secret or /etc/ldap.secret are used. #BINDPWDFILE="/etc/ldapscripts/ldapscripts.passwd" # For older versions of OpenLDAP, it is still possible to use # unsecure command-line passwords by defining the following option # AND commenting the previous one (BINDPWDFILE takes precedence) #BINDPWD="secret" # DEBIAN: values from /etc/pam_ldap.conf are used. SUFFIX="dc=danbishop,dc=org" # Global suffix GSUFFIX="ou=Groups" # Groups ou (just under $SUFFIX) USUFFIX="ou=People" # Users ou (just under $SUFFIX) MSUFFIX="ou=Machines" # Machines ou (just under $SUFFIX) # Start with these IDs *if no entry found in LDAP* GIDSTART="10000" # Group ID UIDSTART="10000" # User ID MIDSTART="20000" # Machine ID # User properties # DEBIAN: values from /etc/adduser.conf are used. #USHELL="/bin/sh" #UHOMES="/home/%u" # You may use %u for username here CREATEHOMES="yes" # Create home directories and set rights ? #HOMESKEL="/etc/skel" # Directory where the skeleton files are located. Ignored if undefined or nonexistant. #HOMEPERMS="755" # Default permissions for home directories # User passwords generation # Command-line used to generate a password for added users (you may use %u for username here) # WARNING !!!! This is evaluated, everything specified here will be run ! # Special value "
" will ask for a password interactively #PASSWORDGEN="cat /dev/random | LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c8" #PASSWORDGEN="head -c8 /dev/random | uuencode -m - | sed -n '2s|=*$||;2p' | sed -e 's|+||g' -e 's|/||g'" PASSWORDGEN="pwgen -s" #PASSWORDGEN="echo changeme" #PASSWORDGEN="echo %u" #PASSWORDGEN=" " # User passwords recording # you can keep trace of generated passwords setting PASSWORDFILE and RECORDPASSWORDS # (useful when performing a massive creation / net rpc vampire) # WARNING !!!! DO NOT FORGET TO DELETE THE GENERATED FILE WHEN DONE ! # WARNING !!!! DO NOT FORGET TO TURN OFF RECORDING WHEN DONE ! RECORDPASSWORDS="no" PASSWORDFILE="/var/log/ldapscripts_passwd.log" # Where to log LOGFILE="/var/log/ldapscripts.log" # Temporary folder TMPDIR="/tmp" # Various binaries used within the scripts # Warning : they also use uuencode, date, grep, sed, cut, expr, which... # Please check they are installed before using these scripts # Note that many of them should come with your OS # OpenLDAP client commands LDAPSEARCHBIN="/usr/bin/ldapsearch" LDAPADDBIN="/usr/bin/ldapadd" LDAPDELETEBIN="/usr/bin/ldapdelete" LDAPMODIFYBIN="/usr/bin/ldapmodify" LDAPMODRDNBIN="/usr/bin/ldapmodrdn" LDAPPASSWDBIN="/usr/bin/ldappasswd" # Character set conversion : $ICONVCHAR <-> UTF-8 # Comment ICONVBIN to disable UTF-8 conversion #ICONVBIN="/usr/bin/iconv" #ICONVCHAR="ISO-8859-15" # Base64 decoding # Comment UUDECODEBIN to disable Base64 decoding #UUDECODEBIN="/usr/bin/uudecode" # Getent command to use - choose the ones used # on your system. Leave blank or comment for auto-guess. # GNU/Linux #GETENTPWCMD="getent passwd" #GETENTGRCMD="getent group" # FreeBSD #GETENTPWCMD="pw usershow" #GETENTGRCMD="pw groupshow" # Auto GETENTPWCMD="" GETENTGRCMD="" # You can specify custom LDIF templates here # Leave empty to use default templates # See *.template.sample for default templates #GTEMPLATE="/path/to/ldapaddgroup.template" #UTEMPLATE="/path/to/ldapadduser.template" #MTEMPLATE="/path/to/ldapaddmachine.template" GTEMPLATE="" UTEMPLATE="" MTEMPLATE=""
The changes from the default file are highlighted below:
# Provides LDAP server's address and the admin username SERVER="ldap://localhost" BINDDN="cn=admin,dc=danbishop,dc=org" # These have all been uncommented, Users changed to People # and the correct suffix set for our domain SUFFIX="dc=danbishop,dc=org" # Global suffix GSUFFIX="ou=Groups" # Groups ou (just under $SUFFIX) USUFFIX="ou=People" # Users ou (just under $SUFFIX) MSUFFIX="ou=Machines" # Machines ou (just under $SUFFIX) # This creates home directories when we create users CREATEHOMES="yes"
On Ubuntu 10.04 there is a bug that causes LONG delays when adding new users. This is to do with the random function used when creating the user’s initial password. There is a very easy work around however, simply change the line “PASSWORDGEN=”cat /dev/random | LC_ALL=C tr -dc ‘a-zA-Z0-9’ | head -c8″” so that /dev/random reads /dev/urandom like so: “#PASSWORDGEN=”cat /dev/random | LC_ALL=C tr -dc ‘a-zA-Z0-9’ | head -c8″”. This bug is fixed in 10.10 and as you can see PASSWORDGEN=”pwgen -s” is used instead.
If you’ve read through the default comments in /etc/ldapscripts/ldapscripts.conf you’ll see that it finds the LDAP admin password from a /etc/ldap.secret file. So the following two commands create that file, write our admin password to it (change PASSWORD to your admin password) and then set it to be non-world-readable. This prevents users discovering your LDAP password, but allows root, or processes running as root, to read the file and find the password.
sudo sh -c "echo -n 'PASSWORD' > /etc/ldap.secret" sudo chmod 400 /etc/ldap.secret
Now the scripts are configured we can start creating users. The first thing to do is create some groups to hold users. The first two groups we will create will be “admin” and “user”. These will later be configured so that users in the admin group can use sudo. This is done like so:
sudo ldapaddgroup admin sudo ldapaddgroup user
Next we will create a user and assign him to a group:
sudo ldapadduser dan admin
Set a password for the user:
sudo ldapsetpasswd dan
And finally add the user to the admin group:
sudo ldapaddusertogroup dan admin
LDAP Authentication on the Server
So LDAP now contains at least one user… how do we login to the server as that user? This is actually very easy to configure, it simply requires the installation of two packages:
sudo apt-get install libnss-ldapd libpam-ldapd
During the configuration section of the installation, you will be asked which services you’d like to enable LDAP for, you should select “group” and “passwd”. The packages will then configure /etc/nsswitch.conf, /etc/pam.d/common-auth and /etc/nslcd.conf to work automatically.
To test your new user login, either logout then try to login with the credentials you created above, or of course, start a new ssh session.