Search code examples
postgresqlsslprivate-keypsql

How to use psql with SSL key?


How to connect to a PostgreSQL server using psql with SSL key just like ssh -i $KEY?


Solution

  • You can use the PGSSLCERT and PGSSLKEY environment variables if you're not using the default locations.

    For example:

    PGSSLMODE=verify-full PGSSLCERT=cert.pem PGSSLKEY=key.pem psql -h servername
    

    Remember to use verify-full for the sslmode, since the other ones won't protect you against MITM attacks.