9951 explained code solutions for 126 technologies


postgresqlHow do I configure PostgreSQL to use Kerberos authentication?


  1. Install the Kerberos client packages on the host running PostgreSQL:
$ sudo apt-get install krb5-user
  1. Create a Kerberos principal for the PostgreSQL user:
$ kadmin.local
kadmin.local:  addprinc postgres/<hostname>
kadmin.local:  exit
  1. Create a keytab file for the PostgreSQL user:
$ kadmin.local
kadmin.local:  ktadd -k /etc/postgresql.keytab postgres/<hostname>
kadmin.local:  exit
  1. Configure the PostgreSQL server to use Kerberos authentication: Edit the file /etc/postgresql/9.6/main/pg_hba.conf and add the following line:
host    all             all             0.0.0.0/0               gss include_realm=0
  1. Restart the PostgreSQL server:
$ sudo service postgresql restart
  1. Configure the Kerberos client on the PostgreSQL host: Edit the file /etc/krb5.conf and add the following lines:
[libdefaults]
    default_realm = <YOUR_REALM>

[realms]
    <YOUR_REALM> = {
        kdc = <KDC_SERVER_IP_ADDRESS>
    }
  1. Test the Kerberos authentication:
$ psql -U postgres -h localhost
Password for user postgres:
psql (9.6.11)
Type "help" for help.

postgres=#

Helpful links

Edit this code on GitHub