Tips Linux/OpenLDAP e SSH

Da GazziNet.
Vai alla navigazione Vai alla ricerca

OpenLDAP e SSH

Questa pagina documenta una configurazione pratica di integrazione tra OpenLDAP e SSH su Ubuntu, con autenticazione utenti centralizzata e privilegi sudo per utente tecnico.

Obiettivo

  • Login SSH con utenza LDAP (es. `gazzinet`)
  • Risoluzione utenti via SSSD/NSS
  • Elevazione privilegi con `sudo`

Parametri LDAP usati

  • URI: `ldap://172.16.1.7:389`
  • Base DN: `dc=gazzi,dc=local`
  • User search base: `ou=People,dc=gazzi,dc=local`
  • Group search base: `ou=Groups,dc=gazzi,dc=local`
  • Bind DN tecnico: `uid=ldapbind,ou=People,dc=gazzi,dc=local`

Pacchetti installati

<syntaxhighlight lang="bash"> apt-get update apt-get install -y sssd-ldap libnss-sss libpam-sss ldap-utils sudo qemu-guest-agent </syntaxhighlight>

Configurazione SSSD

File: `/etc/sssd/sssd.conf`

<syntaxhighlight lang="ini"> [sssd] services = nss, pam config_file_version = 2 domains = GAZZI

[domain/GAZZI] id_provider = ldap auth_provider = ldap chpass_provider = ldap access_provider = permit cache_credentials = True enumerate = False use_fully_qualified_names = False fallback_homedir = /home/%u default_shell = /bin/bash ldap_uri = ldap://172.16.1.7:389 ldap_search_base = dc=gazzi,dc=local ldap_user_search_base = ou=People,dc=gazzi,dc=local ldap_group_search_base = ou=Groups,dc=gazzi,dc=local ldap_default_bind_dn = uid=ldapbind,ou=People,dc=gazzi,dc=local ldap_default_authtok = ******** ldap_user_object_class = inetOrgPerson ldap_user_name = uid ldap_group_object_class = groupOfNames ldap_group_name = cn ldap_tls_reqcert = never ldap_id_use_start_tls = False ldap_auth_disable_tls_never_use_in_production = true </syntaxhighlight>

Note:

  • Il parametro `ldap_auth_disable_tls_never_use_in_production = true` è stato necessario in questo ambiente LDAP non-TLS.
  • In produzione consigliata: LDAP su TLS/LDAPS con certificati validi.

Integrazione NSS/PAM

  • In `/etc/nsswitch.conf` aggiunto `sss` per `passwd`, `group`, `shadow`
  • Home automatica al primo login via `pam_mkhomedir`

Configurazione SSH

File override: `/etc/ssh/sshd_config.d/99-ldap-auth.conf`

<syntaxhighlight lang="text"> UsePAM yes PasswordAuthentication yes KbdInteractiveAuthentication yes PubkeyAuthentication yes </syntaxhighlight>

Sudo per utente LDAP

File: `/etc/sudoers.d/90-gazzinet-ldap`

<syntaxhighlight lang="text"> gazzinet ALL=(ALL:ALL) ALL </syntaxhighlight>

Verifiche effettuate

<syntaxhighlight lang="bash"> getent passwd gazzinet systemctl is-active sssd sshd -T | grep -E 'usepam|passwordauthentication|kbdinteractiveauthentication' </syntaxhighlight>

Test operativo finale:

  • Login SSH come `gazzinet` riuscito
  • `sudo` funzionante con password utente LDAP