LDAP Backup / Restore with slapadd and slapcat



DIR=`date +'%Y%m%d-%H%M'`
mkdir -p $DIR
slapcat -n 0 > $DIR/config.ldif
slapcat -n 1 > $DIR/directory1.ldif




if [ ! -d $DIR ]; then
    echo "$DIR is not a directory"
    exit 1

sudo service slapd stop

sudo rm -rf /var/lib/ldap
sudo mkdir -p /var/lib/ldap

sudo rm -rf /etc/ldap/slap.d
sudo mkdir -p /etc/ldap/slap.d

sudo slapadd -F /etc/ldap/slapd.d -n 0 -l $DIR/config.ldif
sudo slapadd -F /etc/ldap/slapd.d -n 1 -l $DIR/directory1.ldif

sudo chown -R openldap:openldap /var/lib/ldap/
sudo chown -R openldap:openldap /etc/ldap/slap.d

sudo service slapd start

A command to list all users? And how to add, delete, modify users? [Ubuntu]

To list all local users you can use:

cut -d: -f1 /etc/passwd

To list all users capable of authenticating (in some way), including non-local, see this reply: http://askubuntu.com/a/414561/571941

Some more useful user-management commands (also limited to local users):

To add a new user you can use:

sudo adduser new_username


sudo useradd new_username

See also: What is the difference between adduser and useradd?

To remove/delete a user, first you can use:

sudo userdel username

Then you may want to delete the home directory for the deleted user account :

sudo rm -r /home/username

(Please use with caution the above command!)

To modify the username of a user:

usermod -l new_username old_username

To change the password for a user:

sudo passwd username

To change the shell for a user:

sudo chsh username

To change the details for a user (for example real name):

sudo chfn username

And, of course, see also: man adduser, man useradd, man userdel… and so on.