Thursday, 14 December 2017

LDAP

LDAP

Installation

apt-get install slapd
apt-get install ldap-utils
apt-get install ldapvi

Status/start/stop LDAP service

systemctl status slapd
systemctl start slapd
systemctl stop slapd

Configuration

After the packages are installed und slapd is started it is possible to make a first connection test:

ldapsearch -H ldap://127.0.0.1 -x -LLL -b "" -s base +

This command outputs the RootDSE (directory system [agent] entry). By the way scope base is required here otherwise ldapsearch will not return data. The "+" sign means that operational attributes are displayed that normally are hidden.

If this works one can test ldapvi. Ldapvi is a vi based tool to watch, modify and delete LDAP data.

ldapvi -h ldap://127.0.0.1 --bind simple -b "" -s base '(objectclass=*)' +
ldapvi -h ldap://127.0.0.1 --bind simple --discover


The local host address can be omitted:

ldapvi -h ldap:// --bind simple -b "" -s base '(objectclass=*)' + 

Here are explicit commands to get naming contexts and configuration context:

ldapsearch -H ldap:// -x -s base -b "" -LLL "namingContexts"
ldapsearch -H ldap:// -x -s base -b "" -LLL "configContext"


Here are two commands to access the config DN:

ldapsearch -H ldapi:// -Y EXTERNAL -b "cn=config" -LLL -Q
ldapvi -h ldapi:// -Y EXTERNAL -b "cn=config" 


Here is a different URL used. "ldapi" indicates that a unix socket should be used to access the ldapserver with unix sockets the LDAP server is able to identify the user (root of course). The EXTERNAL mechanism utilizes authentication services provided by lower level network services (unix domain sockets).

Command to explore the default domain context:

ldapvi -h ldapi:// -Y EXTERNAL -b "dc=nodomain"

Root Password for the config tree

Create a password hash with slappasswd. Enter the new passwort in the config tree with:

ldapvi -h ldapi:// -Y EXTERNAL -b "cn=config"

Search for "cn=admin,cn=config".  Add or update attribute olcRootPW with the result of slappasswd.

After that it is possible to access the ldap config tree with simple bind (password authentication):

ldapvi -h ldap:// -D "cn=admin,cn=config" -b "cn=config"

Add Schema

Enter the following commands:

ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /etc/ldap/schema/core.ldif 
ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /etc/ldap/schema/cosine.ldif
ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /etc/ldap/schema/inetorgperson.ldif
ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /etc/ldap/schema/inetorgperson.ldif

ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /etc/ldap/schema/nis.ldif

It seems this schemata are already known by Debians LDAP server.

Object classes

To get a list of all defined object classes one can enter this command: 
ldapsearch -H ldap:// -D "cn=admin,cn=config" -W -s base -b "cn=subschema" objectclasses

Rename domain

Openldap was intialized with a domain name (cn=nodomain) which ist not favorable. It can be displayed with this command:

ldapsearch -H ldap:// -D "cn=admin,dc=nodomain" -W -b dc=nodomain -s sub
I was able to delete the manager object within the "nodmain" sub tree but I was not able to delete the domain node itself. I tried it with this commands:

ldapdelete -H ldap:// -D "cn=admin,dc=nodomain" -W dc=nodomain

Or this one. Ldapmodify with an LDIF file:

version: 1
# to apply these changes using ldapvi, run:
#   ldapvi --ldapmodify -h ldap:// ,ldapvi-lamobo-11313.ldif

dn: dc=nodomain
changetype: delete

ldapmodify -H ldap:// -D "cn=admin,dc=nodomain" -W -f ,ldapvi-lamobo-11313.ldif
Here is an explanation why I was not successful.

Next I renamed the suffix as explained here:
olcRootDN: cn=admin,dc=bd,dc=local
olcSuffix: dc=bd,dc=local

I added the top level nodes for my new domain with the following LDIF file:

dn: dc=bd,dc=local
changetype: add
objectClass: top
objectClass: dcObject
objectClass: organization
o: bd.local
dc: bd

dn: cn=admin,dc=bd,dc=local
changetype: add
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
description: LDAP administrator


ldapmodify -x -W -D cn=admin,dc=bd,dc=local -H ldapi:/// -f slapd_setup_basic.ldif
 
After that it is able to access the new DIT with:

ldapvi -h ldap:// -D "cn=admin,dc=bd,dc=local" -b "dc=bd,dc=local" 

Add groupOfEntries class

With this class it is possible to create empty groups. The standard object classes for groups  groupOfNames and groupOfUniqueNames can't do that.

dn: cn=groupofentries,cn=schema,cn=config
objectClass: olcSchemaConfig
cn:groupofentries 
olcobjectclasses:( 1.2.826.0.1.3458854.2.1.1.1 NAME 'groupOfEntries' SUP top STRUCTURAL MUST ( cn ) MAY ( member $ businessCategory $ seeAlso $ owner $ ou $ o $ description ))


ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /tmp/groupOfEntries.ldif

Overlay memberof

The memberof overlay adds automatically the memberOf attribut to users that are members of a groupOfEntries.

dn: cn=module,cn=config
cn: module
objectClass: olcModuleList
olcModuleLoad: memberof
olcModulePath: /usr/lib/ldap

dn: olcOverlay=memberof,olcDatabase={1}mdb,cn=config
changetype: add
objectClass: olcOverlayConfig
objectClass: olcMemberOf
olcOverlay: memberof
olcMemberOfGroupOC: groupOfEntries
olcMemberOfMemberAD: member
olcMemberOfMemberOfAD: memberOf

ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /tmp/memberOf.ldif

Groups and Users

Now we can add some groups and users.

dn: ou=groups,dc=bd,dc=local
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: groups

dn: cn=admins,ou=groups,dc=bd,dc=local
changetype: add
objectClass: top
objectClass: groupOfEntries

dn: cn=users,ou=groups,dc=bd,dc=local
changetype: add
objectClass: top
objectClass: groupOfEntries

dn: ou=people,dc=bd,dc=local
changetype: add
objectClass: top
objectClass: organizationalUnit
ou: people

dn: cn=bdonauba,ou=people,dc=bd,dc=local
changetype: add
objectClass: top
objectClass: person
sn: MyName

ldapadd -x -H ldap:// -D "cn=admin,cn=config" -W -f /tmp/groupUsers.ldif

Attention! The memberOf attribute is operational so one has to use the plus sign with ldapsearch or ldapvi to see it.

Unix Attributes

Of course we want to use openldap as directory for users und groups. To do so we have to enhance the groups with the posixGroup class. For the posixGroup class the gidNumber attribute is mandatory.

cn=admins,ou=groups,dc=bd,dc=local
cn: admins
gidNumber: 10001
objectClass: groupOfEntries
objectClass: posixGroup
objectClass: top


At the moment this is not possible because both groupOfEntries and possixGroup are of type structural, so we change the type of possixGroup to auxiliary.

olcObjectClasses: {2}( 1.3.6.1.1.1.2.2 NAME 'posixGroup' DESC 'Abstraction of a group of accounts' SUP top AUXILIARY MUST ( cn $ gidNumber ) MAY ( userPassword $ memberUid $ description ) )

After this change one can add the posixGroup object class.

Now we can define our first user account.

cn=bdonauba,ou=people,dc=bd,dc=local
sn: Donaubauer
cn: bdonauba
gidNumber: 10001
homeDirectory: /home/bdonauba
loginShell: /bin/bash
objectClass: person
objectClass: posixAccount
objectClass: top
uid: bdonauba
uidNumber: 10001



slapcat -F /etc/ldap/slapd.d/ -H ldap://

dn: dc=bd,dc=l


Wednesday, 10 May 2017

Postgresql

Postgresql

Here is a IMHO nice tutorial: http://www.postgresqltutorial.com

Installation

apt-cache search postgresql
apt-get install postgresql-9.4

Start/Stop

systemctl stop postgresql
systemctl start postgresql
systemctl status postgresql

Configuration

 Login as Postgresql Admin user:
 su - postgres

Move Data Directory

Show the data directory path in pgsql:
SHOW data_directory;
Shut down postgresql DBMS as root:
systemctl stop postgresql
Copy data to hd:
rsync -av /var/lib/postgresql /mnt/data/postgresql
Rename old data directory:
mv /var/lib/postgresql  /var/lib/postgresql.bak
Change  data_directory parameter in postgresql configuration file:
vi /etc/postgresql/9.4/main/postgresql.conf

Set data_directory to the new location:

 data_directory = '/mnt/data/postgresql/9.4/main'
Start postgresql DBMS as root:
systemctl start postgresq
 Change the home directory of user postgres to:
/mnt/data/postgresql

psql

psql commands

List psql commands:
\?
List databases:
\l
 List databases with tablespace: 
\l+
Connect to database:
\c dbname
List tables in the database: 
\dt
Show settings:
show data_directory;
The show command displays the content of configuration parameter. In this case the data directory is displayed.
/mnt/data/postgresql/9.4/main
List sql commands:
\h

Create test database

Start psql an enter this command:
create database mytestdb;
Connect to the new db:
\c mytestdb
Now the database mytestdb is available. In order to create a table enter a create table command:
create table mytesttable (id integer primary key, data char(32));




Tuesday, 27 December 2016

Solution for the power problem of Banana Pi R1

One of the problems of Banana Pi R1 is the insufficient power supply. I was hit by this problem when I added a 1gb disk drive to my R1. The problem revealed when the R1 began stopping to work at once and had to be repowered to work again.

My solution is a different power unit.


I bought a power unit that is normally used for external hard disks. I adapted a Molex y-cable. I replaced the molex socket on one end with a micro USB plug. Now the disk on my R1 is powered directly by the power unit and not by the board. No I have no power problems anymore.


Wednesday, 30 November 2016

Syncthing

I just bought the LG Stylus 2 smart phone, which won't give me access to the SD card as mass storage device, so I installed syncthing as first service on my BPI-R1.

Repository

The first thing to do is to attach the syncthing repository.

curl -s https://syncthing.net/release-key.txt | apt-key add -
echo "deb http://apt.syncthing.net/ syncthing release" | tee /etc/apt/sources.list.d/syncthing-release.list

Next I updated the package cache.

apt-get update

Installation

apt-cache search syncthing
apt-get install syncthing
apt-get install syncthing-inotify

Then I checked what was installed

dpkg-query -L syncthing

Next step was to add a syncthing user

useradd syncthing

Then I linked
  /lib/systemd/system/syncthing@.service
to
  /etc/systemd/system/multi-user.target.wants/syncthing@syncthing.service
in order to start the service in multi user target.

Now enable the Service

systemctl enable syncthing@syncthing.service

First settings

Before I started the service I had to adjust the adress setting in ~/.config/syncthing/config.xml. Normally the syncthing web frontend listens to localhost. I want to be able to access the GUI from everywhere, so I replaced localhost within the address file

    <gui enabled="true" tls="false" debugging="false">
        <address>0.0.0.0:8384</address>
        <apikey>xxxxxxxxxxxxxxxxxxx</apikey>
        <theme>default</theme>
    </gui>

Now it possible to access the GUI from every PC on the LAN. Open a browser and enter the servername
   myserver:8384
in the URL field of the browser.

Share directory

Make a directory

mkdir /mnt/data/syncthing/doc

Enter it in the syncthing web GUI


follow the instructions in the syncthing manual to share directories with other devices.

Hint: If you want to sync to an SD card in an Android phone you have to place the local directory on the phone under the path ...sdcard.../Android/data/com.nutomic.syncthingandroid.files.  Only in this subtree on the SD card syncthing is allowed to write.


   

Monday, 14 November 2016

Very basic NFS configuration

My R1 should work as file server. My other clients have also Linux installed, so I decided to use NFS to get fast and simple access the the R1 hard disk.

Install the NFS server:
apt-get install nfs-kernel-server
Share the fixed disk (mounted on /mnt/data) via NFS:
exportfs *:/mnt/data/
To make the share persistent add in
/etc/exports
the following entry
/mnt/data/       *(rw,sync,no_subtree_check)

Tuesday, 25 October 2016

Installing armbian

 

Now - over a year later - I think it is time for a "relaunch".  I will give armbian a try.

Installation

Before you can install armbian on the board you have to download it from http://www.armbian.com/. At the moment one can choose between an older legacy kernel and an newer vanilla kernel. I took the newer vanilla kernel because I have no need for video acceleration. I want to use my R1 as home server.  When the download is finished you can extract the image of the archive:
7z e archive.7z
Now you have an IMG file. In the next step write the IMG file to the sd card.
dd if=archive.img of=/dev/sdx # replace x by your device number
 After dd stops, sync the file buffers.
sync
Now remove the sd card from your sd card reader and insert it into your R1. Turn it on. If you've done everything right, armbian boots. At the end of the boot process the login prompt is displayed. Log on as root and follow the instruction - you have to change the root password and add a user.

Network

Now you're logged in as root and your network is configured via DHCP.  The default configuration prevents network connections between the ports of the switch. I want my R1 to behave like a simple switch. Fortunately the armbian developers already prepared a network configuration file for this purpose. In /etc/network there is a file interfaces.r1switch. It is the base for my configuration. I copied this file to /etc/network/interfaces an added a static IP address.

auto lo
iface lo inet loopback

auto eth0.101
iface eth0.101 inet manual
    pre-up swconfig dev eth0 set reset 1
    pre-up swconfig dev eth0 set enable_vlan 1
    pre-up swconfig dev eth0 vlan 101 set ports '0 1 2 3 4 8t'
    pre-up swconfig dev eth0 set apply 1

auto wlan0
iface wlan0 inet manual

auto br0
iface br0 inet static
bridge_ports eth0.101 wlan0
  address 192.168.178.2
  netmask 255.255.255.0
  gateway 192.168.178.1
  dns-nameservers 192.168.178.1
At his point I discovered a problem with the swconfig tool. The problem and solution are discussed here. After I installed swconfig from the forum thread everything worked fine.

Update

Now that we have a network connection it is time to update the os.
apt-get update
apt-get upgrade

SATA Disk 

Hint:
When I installed my SATA drive I was hit by one of the shortcoming of this board. Every time I tried to format the disk the board crashed. First I thought the board is defect but then I found out it was the insufficient power supply of this board. I disconnected the USB keyboard and everything worked fine.

To find out the device name list all block devices:
lsblk
Output looks like this:
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 931.5G  0 disk
└─sda1        8:1    0 931.5G  0 part /mnt/data
mmcblk0     179:0    0  28.8G  0 disk
└─mmcblk0p1 179:1    0  28.5G  0 part /
Then format the disk:
mkfs.ext4 /dev/sda1
 Now mount the disk:
mkdir /mnt/data
mount /dev/sda1 /mnt/data
 Add an entry to fstab to make the mount persistent:
/dev/sda1       /mnt/data   ext4   defaults 0 0


Wednesday, 28 September 2016

How it started

Last year I saw this little board with those features I searched so long for.

A mixture of:
  • switch
  • access point
  • home server
It looked like a "eierlegende Wollmilchsau". A device that meets all my needs and a whole bunch of operating systems available. So I ordered it on the Internet. A few days later I had my device at home. At the same evening my enthusiasm was replaced by disillusion. Nothing seemed to work out of the box. I recognized I was at the beginning of a long and rocky track. I was able to knock a basic configuration together based on Bananian 15.04. This included compiling the WLAN driver and hostapd. Then I paused my work.

The technological shortcomings of this boards are:

Links:
Site of the bananian operating system. 
Site of armbian operating system