Central Authentication & Authorization Service For RedHat Environment With Active Directory

Central Authentication & Authorization Service For RedHat Environment With Active Directory

This method uses Microsoft Active Directory service for a central authentication & authorization of users.


This method uses Microsoft Active Directory service for a central authentication & authorization of users. When creating account for users in AD, their public key is also stored as a parameter within the AD. When a user tries to login into a Red-hat server using private key, the sshd service checks if user accounts exist by communicating with AD via sssd service. If the user exists, then sshd service runs a script to fetch the public key of that user (stored in a parameter on AD). The user is then authenticated and successfully logged in. The new users can be created, and older user can be disabled from a central location. All other advance AD features can be used with Linux servers as well.



1. Integration of Linux Hosts with Active Directory


Network Changes

Edit the file /etc/resolv.conf and add Active Directory Domain Controller


search AD1.example.com AD1
nameserver <IP-address of AD1>

Add a new entry in the file /etc/hosts


<IP-address of AD1> AD1.example.com AD1


Install Required Packages

Install following packages to connect to Active Directory.


yum install sssd realmd oddjob oddjob-mkhomedir adcli samba-common samba-common-tools krb5-workstation openldap-clients policycoreutils-python


Connection to Domain Controller

Use the following command to connect to Domain


realm join --user=administrator example.com

Edit the file /etc/sssd/sssd.conf and add a new service and tag for ssh


services = nss, pam, ssh
[ssh]

Change the following


use_fully_qualified_names = False
fallback_homedir = /home/%u

and add a line at the end


ldap_user_ssh_public_key = userParameters


To check the connectivity with Domain, restart sssd service.


systemctl restart sssd

Now try to fetch account info from Domain


id administrator


Configure SSH Authentication

Edit file /etc/ssh/sshd_config and make following changes


AuthorizedKeysCommand /opt/ldap.sh
AuthorizedKeysCommandUser nobody

To disable password logins


PasswordAuthentication no
ChallengeResponseAuthentication no


LDAP Script

Create a script as /opt/ldap.sh


#!/bin/bash
q="$(echo $1 | cut -d'@' -f 1)"
num="$(ldapsearch -h AD1.example.com -x -w <passowrd-for-account> -D "[email protected]" -b "dc=AD1,dc=example,dc=com" "sAMAccountName=$q" -s sub "objectclass=*" userParameters -LLL -o ldif-wrap=no | grep ssh-rsa | cut -d':' -f 2)"
echo $num
The script runs a ldap query against the Domain server to fetch the public key.It needs the password for auth account as well as execute permissions chmod +x /opt/ldap. The auth account needs to be created on AD(with minimum permissions).


Grant Sudo Access

Create a sudoers group on Domain server and edit the file on Linux using


visudo -f /etc/sudoers

and Add the following entry at the end


%server.domain.com\\sudoers ALL=(ALL) NOPASSWD: ALL


Needs to restart sssd & sshd service


systemctl restart sssd
systemctl restart sshd


2. Public Keys implementation in Active Directory

In Users & Groups Section, Go to the User properties, from the Attribute Editor tab change the paramter userParameters and paste the public key.


To show the Attribute Editor tab look in to the views tab to show Advance features. Puttygen can be used for creating Private/Public Keys.


Troubleshooting Tips

In-case of authentication errors.


Check if you can get the public key by running the script manually.


/opt/ldap <username>

Check if Se-Linux is blocking your script from running.


set-enforce 0

Try running ssh with debug option & tail the logs for errors.


ssh user@server -i private.key -vvv

tail -f /var/log/secure
  • Tags:
  • No tags

Comments (0)

Leave a Reply

Log in to post a comment.