Ubuntu 14.04 Ultimate Server Guide

Part 6: Account Management

Now you have OpenLDAP and Kerberos 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 Gana�l LAPLANCHE - Linagora
#  Copyright (C) 2006-2011 Gana�l LAPLANCHE
#
#  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 server
# DEBIAN: values from /etc/pam_ldap.conf are used.
SERVER="ldap://localhost"
BINDDN="cn=admin,dc=danbishop,dc=org"
# Suffixes
# 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=Users"         # Users ou (just under $SUFFIX)
MSUFFIX="ou=Machines"      # Machines ou (just under $SUFFIX)

# Authentication type
# If empty, use simple authentication
# Else, use the value as an SASL authentication mechanism
SASLAUTH=""
#SASLAUTH="GSSAPI"

# Simple authentication parameters
# DEBIAN: values from /etc/pam_ldap.conf are used.
# The following BIND* parameters are ignored if SASLAUTH is set
#BINDDN="cn=Manager,dc=example,dc=com"
# 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"

# Start with these IDs *if no entry found in LDAP*
GIDSTART="10000" # Group ID
UIDSTART="10000" # User ID
MIDSTART="20000" # Machine ID

# Group membership management
# ObjectCLass used for groups
# Possible values : posixGroup, groupOfNames, groupOfUniqueNames (case-sensitive !)
# Warning : when using groupOf*, be sure to be compliant with RFC 2307bis (AUXILIARY posixGroup).
# Also, do not mix posixGroup and groupOf* entries up in you directory as, within RFC 2307bis,
# the former is a subset of the latter. The ldapscripts wouldn't cope well with this configuration.
GCLASS="posixGroup"   # Leave "posixGroup" here if not sure !
# When using  groupOfNames or groupOfUniqueNames, creating a group requires an initial
# member. Specify it below, you will be able to remove it once groups are populated.
#GDUMMYMEMBER="uid=dummy,$USUFFIX,$SUFFIX"

# 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 ; special value "" will ask for a password interactively
# WARNING    !!!! This is evaluated, everything specified here will be run !
# WARNING(2) !!!! Some systems (Linux) use a blocking /dev/random (waiting for enough entropy).
#                 In this case, consider using /dev/urandom instead.
#PASSWORDGEN="cat /dev/random | LC_ALL=C tr -dc 'a-zA-Z0-9' | head -c8"
#PASSWORDGEN="pwgen"
#PASSWORDGEN="echo changeme"
#PASSWORDGEN="echo %u"
#PASSWORDGEN=""
PASSWORDGEN="pwgen"

# 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=Users"         # Users ou (just under $SUFFIX)
MSUFFIX="ou=Machines"      # Machines ou (just under $SUFFIX)

# This creates home directories when we create users
CREATEHOMES="yes"

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/ldapscripts/ldapscripts.passwd 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/ldapscripts/ldapscripts.passwd"
sudo chmod 400 /etc/ldapscripts/ldapscripts.passwd

You might also have noticed that /etc/adduser.conf is used to determine home directory defaults. Ubuntu allows users to view the contents of other user’s home directories by default. In some environments, particularly home environments, this is fine, but you might want to change that by editing DIR_MODE=0755 to be DIR_MODE=0700.

Managing Users

Now the LDAP scripts are configured we can start creating users. We’re going to use the group name “domainadmins” for administrators to differentiate from the default “admin” or “sudo” group for local Ubuntu users. This will enable us to give admin rights to users on every machine on the network without any further configuration.

The first thing to do is create a password for our first admin user. As we are using Kerberos for authentication, the administrator needs a principal creating. This is done like so:

sudo kadmin.local -q "addprinc dan"

Now we need some groups to hold our users. The first two groups we will create will be “domainadmins” and “domainusers”:

sudo ldapaddgroup domainadmins
sudo ldapaddgroup domainusers

Next we will create a user and assign him to the admins group:

sudo ldapadduser dan domainadmins

And finally add the user to the users group too:

sudo ldapaddusertogroup dan domainusers

You can now login to the server (and later client machines) as this user. If you added sudo to LDAP earlier, as instructed in the OpenLDAP section, then sssd will handle this automatically on the server and users in the group “domainadmins” will have sudo rights on the server – be careful who you assign to this group!

References

http://www.opinsys.fi/en/setting-up-openldap-on-ubuntu-10-04-alpha2

  • Florent

    Hi Dan !
    Thank you for your great work, as usual 🙂

    I have an error on part 7, like another follower of your 12.04 guide (http://www.danbishop.org/2012/06/02/ubuntu-12-04-ultimate-server-guide/#comment-1552860993).
    Command kadmin -p dan/admin -q “addprinc -randkey nfs/$(hostname -f)” failed with :
    Authenticating as principal dan/admin with password.
    kadmin: Cannot resolve network address for admin server in requested realm while initializing kadmin interface

    Moreover, after restart sssd, it is impossible to connect to LDAP user with su, and getent passwd only shows local user.
    I think there is a problem between client and server. Evertyhing works fine on server side, and client can ping server through kerberos.domain.local and ldap.domain.local.

    Thank you for your help

    • danbishop88

      Hi Florent,

      Try appending -s kerberos.domain.local to that command and see what happens. It looks like you’re customising some parts of the guide for your own environment, but not others… it’s possible that your /etc/krb5.conf file on the client is wrong.

      I’m hoping to have a way of doing all of this using puppet going very soon. I’m almost there and will hopefully publish in the next couple of weeks. That should eliminate all the problems people are having by varying parts of the guide for their environment, but not others.

      Dan

      • Florent

        Thank you very much for your answer.
        I reinstall server & client. No customising except domain (domain.local) and kerberos username as florent/admin. On the client side, sudo dpkg-reconfigure krb5-config only ask realm but server and admin server where difined during installation. My /etc/krb5.conf file seems to be good. My domain isn’t defined in [domain_realm] but it is in [libdefaults]. Servers name are in top of [realms] (kdc and admin_server).
        Is there au place where krb logs ?

        Thanks again.
        Florent

    • Hi Florent,

      i run accoss the same problem as you have, after several tryout found out that you need to point you DNS Client into IP of Server.

      ie. DNS Client is : 8.8.8.8 from Network Manager, then you change to 192.168.1.100 (IP of Ubuntu Server)

      and voila :)… Hope this helps !

    • aqw

      I also got this error and solved it by adding 192.168.0.2 kerberos.danbishop.org to /etc/hosts of the client machine

    • OleHoppe

      Solved this issue by editing /etc/nsswitch.conf on the client (kubuntu 16.04.2). Modify “hosts” line to read:
      hosts: files dns
      HTH

  • Marco

    Hi Dan, thanks for this beatifoul guide

    i try many times your guide but have some problem

    server configure as your guide
    when try login from a configured client (using server username) it log succesfull but unable to mount home directory

    “Could not chdir to home directory /home/fabio: No such file or directory”

    check and check again but still this problem….

    can you help me?

    • Marco

      I have only linux (debian) pc, i’m interested central accounting and share users home directory… samba in future (now not important)

      ubuntu 14 server configure as your VERY clear guide (and thanks!!)
      i’m able lo ssh login on server using LDAP user accounts and is fantastic

      then want allow login from clients, pc… configure as guide… login is accepted but NO home directory mounted

      how i can debug where problem is?

      Sorry for my english

      • GuiSenges

        Hello Marco,

        I got the same problem. Any news? I’ve double checked this tutorial multiple times and everthing seems ok…

        • GuiSenges

          Small Update: When running automount in verbose mode I get “mount(nfs): no hosts available”. NFS server is up and running…Very strange…

        • GuiSenges

          Ok, I figured it out: Ports 111 and 2049 both TCP and UDP needs to be openned….Thanks for the excelent tutorial Dan!

        • Marco

          In my case there was no firewall…

        • Marco

          Problem solved, was a problem with reverse resolution… because i have an existing bind dns server and need use it, can’t use dnsmasq. Now NFS/kerberos works perfect!!
          Tanks for this perfect, clean guide DAN!!

          Now going on to configure samba, but i have a problem again (sorry!!): windows PC can see samba share but can join to samba domain. When try to join samba domain from a windows pc, it ask user name and password (i use my user (domainuser) with net rpc rights grant) but give me an error… each username and password i try to use same error…

    • Hi Marco,

      i have the same situation as you are, can you help me out the solutions here ?

  • Marco

    Hi again,
    i have this strange problem:

    if i reinstal ubuntu on server, add again ldap users, kerberos etc etc (as in this guide)

    clients can’t mount their home using nfs

    try to login one from client, perform again:
    kadmin -p dan/admin -q “addprinc -randkey nfs/$(hostname -f)”
    sudo kadmin -p dan/admin -q “ktadd nfs/$(hostname -f)”
    but nothink happens

    if i reinstall ubuntu on client pc, follow client configuration (of this guide) all return perfect working

    I think problem is Kerberos, but how to solve this problmem when i reinstall OS on server?
    try to remove nfs princ from server but not solution

    any advices?
    thanks

    • Hi Marco,

      happens to be the same issue with me as well,
      but instead of reformatting ubuntu client, here are what i did :

      apt-get purge –remove krb5-user -y
      REBOOT NOW !

      apt-get install krb5-user -y
      dpkg-reconfigure krb5-config

      sudo kadmin -p dan/admin -q “addprinc -randkey nfs/$(hostname -f)”
      sudo kadmin -p dan/admin -q “ktadd nfs/$(hostname -f)”

      REBOOT NOW !

      and you can easily login with your domain users credentials 🙂

      (PS : your guess is right it is somehow connected to Kerberos, but no need to remove nfs princ 🙂

      • Marco

        Hi,
        thanks for this solution!

  • Steve Thompson

    Hi,
    Thanks for the great guide. I have a question about this setup – I also had this problem with the 12.04 guide. In both, you set neo to have a static IP and then you configure dnsmasq to use Google’s public servers. At no point, as far as I can see, do you tell neo which DNS servers to use which means it has no DNS. I’ve added dns-nameservers 127.0.0.1 to the static config to get round this but I can’t figure out if I’m missing something in the instructions that would make this unnecessary?

    Thanks

  • Hi Dan, just a quick correction,

    on Page 6
    there is something like

    #BINDPWDFILE=”/etc/ldapscripts/ldapscripts.passwd”

    it should be not comment (remove the hashtag)

    otherwise it will come out results

    “Unable to read password file , exiting…”

    But overall this is Awesome tutorials :))

    • Thanks Adhi… I had the same issue. Great guide by the way, Dan 😀

  • Marco

    Hi, i have new problem

    new workstation wit Windows 10 need to be joined to Samba

    not no succes 🙁

    no problem when add windows7 macchines

  • Ian Carey

    The package ldapscripts didn’t work for me. I used ldap-account-manager instead.

    For Samba, by default you get Samba 4. Your command “adminlocal@neo:$ net rpc rights grant -U dan “danbishop.orgDomain Admins” SeMachineAccountPrivilege SePrintOperatorPrivilege SeAddUsersPrivilege SeDiskOperatorPrivilege SeRemoteShutdownPrivilege” is depreciated and will not work with Samba 4.

    Fix is a new syntax below.

    net sam rights grant “danbishop.orgDomain Admins” SeMachineAccountPrivilege SePrintOperatorPrivilege SeAddUsersPrivilege SeDiskOperatorPrivilege SeRemoteShutdownPrivilege -Udan

    Other than those two things I have it all up and running perfectly. Thank you Dan!

  • Jheguy2

    I’ve been getting the error:
    Error adding group domainadmins to LDAP
    every time I try and create a new group. I’ve checked the logs and they are returning:
    ldap_add: No such object (32)
    If anyone could help me I would be more than grateful. Thank you.

    • Pekka R.

      Had similar problem. Did not check the logs, so not completely sure if same problem.
      I commented line BINDDN=”cn=Manager,dc=example,dc=com” from

      /etc/ldapscripts/ldapscripts.conf
      since similar line was already added for actual DN by Dan’s instructions.

    • Dheeraj Bharat Sethi

      Hi there, In just faced the same issue, can you please let me know the solution for the same?
      Thanku

      • Dheeraj Bharat Sethi

        Got it resolved, adding password by vi was causing the issue.

  • Olivier Dir

    hi all after client install (ubuntu 14.04) without error
    i don’t found domainadmins with command getent group
    how do to debug this point ?

    where is the log file for see if there are a problem ?

    thank for your help

  • Marco

    All works fantastic (10months perfect working)
    but now i have new workstation with windows10 preinstalled, want join them tho ubuntu domain
    follow same guide than win7 but win10 give me an error, not join into domain giving an error (unable to contact domain)

    any help?

  • Kleder Osodarck

    Hello Dan!

    First thanks for the great tutorial!

    I’m using your guide to build an GNS3 network for a college project, the problem is I have to join Windows XP and 2000 machines in the domain, any information or direction on how to do so will be really appreciated! below is the error I’m receiving in a Windows XP machine:

    error 0x000005B4 ERROR_TIMEOUT

  • John Christensen

    I am not having luck getting Windows 7 to connect to the Samba DC. The error I am getting says that windows was trying to contact the SRV record for _ldap._tcp.dc._msdcs.. I added a SVR record to dnsmasq.conf and pointed the requests to ldap. on port 398. Now I am getting an error from Windows that the domain controller at ldap. could not be reached. Any thoughts on why this is not working for me?

  • TC

    On Ubuntu 15.10, I failed at Step 6, “sudo ldapaddgroup domainadmins”. In /var/log/ldapscripts.log, the error message is ldapadd: invalid format (line 1) entry “”. It turns out it is a bug in ldapscripts—it fails in some locales. For more information, read this:

    https://github.com/martymac/ldapscripts/issues/3

    You can fix this bugs by these commands:

    sudo su
    LC_ALL=C ldapaddgroup domainadmins
    LC_ALL=C ldapaddgroup domainusers
    LC_ALL=C ldapadduser csatc2002 domainadmins
    LC_ALL=C ldapaddusertogroup csatc2002 domainusers

    Just my two cents, and hope it helps.

  • Thanks a lot, Dan.
    I migrated the authentication of a cluster of machines with Ubuntu 14.04 from NIS to LDAP+Kerberos and it worked great. I tried to follow the instructions for SingleSignOn from the Ubuntu Help but it was very complicated, didn’t explain some concepts and contained some “magical” instructions. This guide help me figure out what I needed to do.

  • Srinath Bk

    Hi Dan,

    thanks for the excellent tutorial.

    I cannot use DHCP server for my setup since, there is already another DHCP server in the LAN. I would like to use static IP for both server and clients. Can you please suggest what needs to be changed?

    regards,
    Srinath

  • Dheeraj Bharat Sethi

    Hi dan,
    Thanku so much for the guide.
    been stuck on last step. when trying to login via the new ldap user.
    “No passwd entry for user”
    When trying to add passwd, “user does not exist”
    What is going wrong here?
    Thanku

  • Dheeraj Bharat Sethi

    Getting Permission Denied via SSH for the Ldap user added , and Incorrect Login via server login

  • Hello Dan,

    Are there any GUI based apps for managing Sudoer Rules in LDAP? Using a
    LDAP Browser is not a very user-friendly way for managing a large number
    of Sudo Rules. FreeIPA has a UI for managing Sudoer Rules, but it
    requires 389 Directory Server, and we don’t use that in our environment
    (for good reasons)

  • Bineural juls

    Hi, i think all its working ok, but as sson as i login by ssh with user i have this error.. Could not chdir to home directory /home/robert: No such file or directory
    And localy on the machine this one:
    No directory, logging in with HOME=/
    I can see the problem is that my home is not working.. but i dunno how to solve this.
    Any idea please?
    Thanks a lot

  • Pekka R.

    Salut!
    This is still the most clear and complete guide to set up a small company network environment with servers. I can not find better. And I have looked around. Just bloody exellent. “Ultimate” describes this well.
    Did finally have time to look at chapter 10. Just wondering what does mean “In this case a stock install of 12.04 server is being used” in this context.

    Dan? Does it mean a copy of the primary server installation that I could make with dd command and then twist around the dnsmasq configuration file?

    Maybe safest option is to start installing server from the start and follow up the master server setup instructions untill this point. I expect that the /etc/dnsmasq.conf file will be mirror of the master dnsmasq server regarding to ip-adresses and host names. Will start playing with image copied with dd first.

    Many thanks to Dan for giving this to public domain. To boil up this kind of instruction set so, that it is also comprehensible, must have taken a ton of work.

  • Gin

    Great guide and working one 🙂
    Any chance to update same tutorial for Ubuntu 16.04? Or maybe a little help pls. Things seems working till samba setup. First of all in Ubuntu 16.04 libpam-smbpass was removed. So I add user manually for krb and samba using same credentials (even account for machine in some tests). When i try to join an Windows 7 to domain I got follow error:
    “The join operation was not successful. The could be because an existing computer account having the name xxxx was previously created using a different set of credentials. Use a different computer name or contact your administrator to remove any stale conflicting raccount. The error was: Access is denied.”
    Ldap log:
    Jan 31 13:58:59 dcdoxmain slapd[1539]: conn=1052 fd=20 ACCEPT from IP=xxx.xxx.xxx.xxx (IP=0.0.0.0:389)
    Jan 31 13:58:59 dcdoxmain slapd[1539]: conn=1052 op=0 BIND dn=”” method=163
    Jan 31 13:58:59 dcdoxmain slapd[1539]: SASL [conn=1052] Failure: GSSAPI Error: An unsupported mechanism was requested (Unknown error)
    Jan 31 13:58:59 dcdoxmain slapd[1539]: conn=1052 op=0 RESULT tag=97 err=49 text=SASL(-13): authentication failure: GSSAPI Failure: gss_accept_sec_context
    Samba shares could be accessed from Windows 7 using same credentials.

  • Marco

    Hi again DAN, thanks again for this beatifoul guide… i’m using it in my office and works like a charm!!
    I’m really happy to have Win7 and Linux (debian) with distributed logins, home directories!
    Now i really have a bit headache trying join new windows 10 pro macchines to samba domain… i try many many different samba configuration but no solution.
    You know any solution?

    Thanks