Linux Restrict Server Login via LDAP hostObject objectClass and host Attribute

• Updated January 10, 2019

It is possible to restrict Linux server login via LDAP by using the hostObject objectClass and host attribute.

Each LDAP user that you want to restrict login access to should have the hostObject objectClass so the host attribute becomes available to that LDAP user. Each LDAP user will have as many host attributes as there are servers that user needs access to.

Each Linux server that is being restricted access to also needs to have the pam_check_host_attr parameter set to yes in the /etc/pam_ldap.conf file.

Take note, this solution does not scale well. If a new client sever comes online it will have to be added to every LDAP user needing access. This can of course be scripted, but a more scalable solution is to use LDAP groups.

Nevertheless, continue reading for setup instructions.

In this example, jbond will be the LDAP user we want to restrict access for. jbond will only need access to client servers and

Client Server Setup

It is assumed the client server can already talk to the LDAP server.

The only necessary change on each client server is to add the following to /etc/pam_ldap.conf:

pam_check_host_attr yes

At this point, local users can login normally, but LDAP users must have objectClass: hostObject and host: and/or host: in their LDAP user entry to gain access to either of those servers.

LDAP Server Setup

Add hostObject objectClass and host Attribute(s) to LDAP User

Log in to the LDAP server and issue the following command:

ldapmodify -x -D "cn=Directory Manager" -W -S errors.txt -c

After successfully authenticating as the Directory Manager user, you will be on a blank line where the command line is waiting for input. To add the hostObject objectClass and the host attributes to LDAP user jbond, copy and paste the following into the command line:

dn: uid=jbond,ou=People,dc=example,dc=com
changetype: modify
add: objectClass
objectClass: hostObject
add: host

If you make a mistake type Ctrl + C to exit out of the command and no modifications will be done.

To apply the changes, type Ctrl + D to commit the changes and exit or type Enter twice. A successful modification will show modifying entry “uid=jbond,ou=People,dc=example,dc=com”.

Remove host Attribute(s) from LDAP User

If you need to remove a host attribute from an LDAP user, because that LDAP user is no longer allowed to access that client server, then follow the same process as the section above but copy and paste the following into the command line:

dn: uid=jbond,ou=People,dc=example,dc=com
changetype: modify
delete: host

If you want to remove several host attributes at once, add another host attribute line to the above content such as host:

Remove hostObject objectClass from LDAP User

If you no longer want any host attributes or the hostObject objectClass applied to an LDAP user, then follow the same process as the section above but copy and paste the following into the command line:

dn: uid=jbond,ou=People,dc=example,dc=com
changetype: modify
delete: host
delete: objectClass
objectClass: hostObject

ldapmodify via a File

All of the above modifications can also be done by placing the respective content in a file and running:

ldapmodify -x -D "cn=Directory Manager" -W -S errors.txt -c -f modifications.ldif

View the LDAP User

To verify any changes above were actually applied, perform an ldapsearch on the LDAP user from any client able to talk to the LDAP server:

ldapsearch -x "uid=jbond"


active-directory (1)

ads (1)

aix (2)

ambient-noise (1)

amd (2)

android (1)

ansible (6)

apache (2)

api (2)

apple (7)

apple-tv (1)

apt (1)

awk (1)

bash (1)

bittorrent (2)

bootstrap (3)

centos (7)

cheat-sheet (14)

chef (1)

chromeos (1)

cloud (1)

cmatrix (1)

cobbler (3)

cowboy-bebop (1)

curl (1)

darwin-streaming-server (1)

datadog (1)

ddclient (1)

debian (2)

dell (3)

development (2)

diagrams (2)

disqus (1)

dlna (1)

dns (1)

docker (1)

documentation (153)

doxie (2)

dvdbackup (1)

ejabberd (2)

exiftool (1)

fedora (6)

ffmpeg (2)

filevault (1)

find (1)

firefly (1)

git (1)

glance (1)

gluster (2)

gnome (1)

golang (1)

google-app-engine (2)

google-chrome (1)

google-chromecast (1)

google-cloud-dns (1)

google-cloud-functions (1)

google-cloud-platform (5)

google-cloud-pubsub (1)

google-drive (1)

google-kubernetes-engine (1)

handbrake (1)

icloud (2)

idrac (3)

imagemagick (1)

ios (3)

iphone (3)

iscsi (1)

java (1)

javascript (1)

jekyll (6)

jquery (3)

json (3)

kerberos (1)

keystone (1)

kickstart-profiles (7)

kubernetes (2)

kvm (2)

ldap (6)

lego (1)

lets-encrypt (1)

linux (18)

macbook (3)

macos (2)

markdown (1)

mdadm (1)

mechanical-keyboards (1)

megacli (1)

microdata (1)

msi-gs65-stealth-thin (2)

mysql (1)

namecheap (1)

networking (1)

neutron (2)

nfs (1)

nova-network (2)

openssl (2)

openstack (21)

opinions (9)

os-x (4)

os-x-mavericks (1)

os-x-mountain-lion (2)

os-x-yosemite (6)

parted (1)

preseed (1)

python (4)

quantum (1)

racadm (2)

rackspace-private-cloud (3)

raid (2)

red-hat (8)

red-hat-satellite-server (2)

reviews (7)

rfid (1)

rhel (7)

rpm (1)

rss (1)

safari (1)

samsung (1)

scp (1)

scsi (1)

security (3)

sed (1)

seo (2)

shell (10)

skippy (2)

snappass (1)

solaris (3)

spotlight (1)

ssd (2)

ssh (1)

sshpass (1)

ssl (1)

sssd (1)

stackdriver (1)

star-wars (1)

steam (1)

storage (1)

support (2)

swift (6)

terminal (1)

thinkpad (1)

transmission (2)

troubleshooting (1)

ubuntu (9)

usb-c (1)

vagrant (11)

varnish (2)

virtualbox (8)

vmware-fusion (10)

wallets (1)

web-analytics (1)

wifi (1)

windows (2)

windows-10 (1)

windows-7 (2)

windows-server (1)

world-of-warcraft (1)

xrdp (1)

xserver (1)

zfs (1)