Using psql to connect to PostgreSQL in SSL mode

后端 未结 7 1442
攒了一身酷
攒了一身酷 2021-01-30 07:50

I am trying to configure ssl certificate for PostgreSQL server. I have created a certificate file (server.crt) and key (server.key) in data directory and update the parameter SS

相关标签:
7条回答
  • 2021-01-30 08:34

    On psql client v12, I could not find option in psql client to activate sslmode=verify-full.

    I ended up using environment variables :

    PGSSLMODE=verify-full PGSSLROOTCERT=server-ca.pem psql -h your_host -U your_user -W -d your_db
    
    0 讨论(0)
  • 2021-01-30 08:35

    Well, you cloud provide all the information with following command in CLI, if connection requires in SSL mode:

    psql "sslmode=verify-ca sslrootcert=server-ca.pem sslcert=client-cert.pem sslkey=client-key.pem hostaddr=your_host port=5432 user=your_user dbname=your_db" 
    
    0 讨论(0)
  • 2021-01-30 08:39

    psql "sslmode=require host=localhost port=2345 dbname=postgres" --username=some_user

    According to the postgres psql documentation, only the connection parameters should go in the conninfo string(that's why in our example, --username is not inside that string)

    0 讨论(0)
  • 2021-01-30 08:45

    psql below 9.2 does not accept this URL-like syntax for options.

    The use of SSL can be driven by the sslmode=value option on the command line or the PGSSLMODE environment variable, but the default being prefer, SSL connections will be tried first automatically without specifying anything.

    Example with a conninfo string (updated for psql 8.4)

    psql "sslmode=require host=localhost dbname=test"
    

    Read the manual page for more options.

    0 讨论(0)
  • 2021-01-30 08:45
    psql -h <host> -p <port> -U <user> -d <db>
    

    and update /var/lib/pgsql/10/data/pg_hba.conf to change the auth method to cert. Check the following link for more information:

    https://www.postgresql.org/docs/9.1/auth-pg-hba-conf.html

    0 讨论(0)
  • 2021-01-30 08:51

    Found the following options useful to provide all the files for a self signed postgres instance

    psql "host={hostname} sslmode=prefer sslrootcert={ca-cert.pem} sslcert={client-cert.pem} sslkey={client-key.pem} port={port} user={user} dbname={db}"
    
    0 讨论(0)
提交回复
热议问题