使用psql以ssl模式连接到Postgresql [英] Using psql to connect to postgresql in ssl mode
问题描述
我正在尝试为postgreSQL服务器配置ssl证书。我已经在数据目录中创建了一个证书文件(server.crt)和密钥(server.key),并将参数SSL更新为 on以启用安全连接。
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 SSL to "on" to enable secure connection.
我只希望仅在客户端使用服务器证书对服务器进行身份验证,而不要求在服务器端使用客户端的真实性。我使用psql作为连接和执行命令的客户端。
I just want only the server to be authenticated with server certificates on the client side and dont require the authenticity of client at server side. I am using psql as a client to connect and execute the commands.
我使用 PostgreSQL 8.4 和linux。我尝试使用以下命令连接到启用了ssl的服务器
I am using PostgreSQL 8.4 and linux. I tried with the below command to connect to server with ssl enabled
psql "postgresql://localhost:2345/postgres?sslmode=require"
但是我得到
psql: invalid connection option "postgresql://localhost:2345/postgres?sslmode"
这是怎么了?我尝试在启用ssl模式的情况下连接服务器的方法是否正确?只验证服务器而不验证客户端是否可以?
What am doing wrong here? Is the way I am trying to connect to server with ssl mode enabled is correct? Is it fine to authenticate only server and not the client ?
请帮帮我。
推荐答案
psql
不接受选项的这种类似URL的语法。
psql
below 9.2 does not accept this URL-like syntax for options.
可以通过命令行上的 sslmode = value
选项或 PGSSLMODE 环境变量,但默认值为 prefer
,将首先自动尝试不指定任何内容的SSL连接。
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.
带有conninfo字符串的示例(已针对psql 8.4更新 >)
Example with a conninfo string (updated for psql 8.4)
psql "sslmode=require host=localhost dbname=test"
阅读手册页获取更多选项。
这篇关于使用psql以ssl模式连接到Postgresql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!