本文翻译自:Getting error: Peer authentication failed for user “postgres”, when trying to get pgsql working with rails

I'm getting the error: 我收到错误:

FATAL: Peer authentication failed for user "postgres"

when I try to make postgres work with Rails. 当我尝试使用Rails进行postgres时。

Here's my pg_hba.conf , my database.yml , and a dump of the full trace . 这是我的pg_hba.conf ,我的database.yml ,以及完整跟踪的转储 。

I changed authentication to md5 in pg_hba and tried different things, but none seem to work. 我在pg_hba中将身份验证更改为md5并尝试了不同的操作,但似乎都没有。

I also tried creating a new user and database as per Rails 3.2, FATAL: Peer authentication failed for user (PG::Error) 我还尝试按照Rails 3.2创建一个新的用户和数据库,致命:用户的对等身份验证失败(PG ::错误)

But they don't show up on pgadmin or even when I run sudo -u postgres psql -l . 但是他们没有出现在pgadmin上,甚至当我运行sudo -u postgres psql -l

Any idea where I'm going wrong? 知道我哪里错了吗?


#1楼

参考:https://stackoom.com/question/1GJNS/获取错误-当试图让pgsql使用rails时-用户-postgres-的对等身份验证失败


#2楼

The problem is still your pg_hba.conf file ( /etc/postgresql/9.1/main/pg_hba.conf* ). 问题仍然是你的pg_hba.conf文件( /etc/postgresql/9.1/main/pg_hba.conf* )。

This line: 这一行:

local   all             postgres                                peer

Should be: 应该:

local   all             postgres                                md5

* If you can't find this file, running locate pg_hba.conf should show you where the file is. *如果找不到此文件,运行locate pg_hba.conf应该会显示该文件的位置。

After altering this file, don't forget to restart your PostgreSQL server. 更改此文件后,请不要忘记重新启动PostgreSQL服务器。 If you're on Linux, that would be sudo service postgresql restart . 如果你在Linux上,那将是sudo service postgresql restart

These are brief descriptions of both options according to the official PostgreSQL docs on authentication methods . 这些是根据官方PostgreSQL文档关于身份验证方法的两个选项的简要描述。

Peer authentication 对等身份验证

The peer authentication method works by obtaining the client's operating system user name from the kernel and using it as the allowed database user name (with optional user name mapping). 对等身份验证方法的工作原理是从内核获取客户端的操作系统用户名,并将其用作允许的数据库用户名(使用可选的用户名映射)。 This method is only supported on local connections. 仅在本地连接上支持此方法。

Password authentication 密码验证

The password-based authentication methods are md5 and password. 基于密码的身份验证方法是md5和密码。 These methods operate similarly except for the way that the password is sent across the connection, namely MD5-hashed and clear-text respectively. 除了通过连接发送密码的方式外,这些方法的操作类似,分别是MD5散列和明文。

If you are at all concerned about password "sniffing" attacks then md5 is preferred. 如果你完全担心密码“嗅探”攻击,那么首选md5。 Plain password should always be avoided if possible. 如果可能,应始终避免使用普通密码。 However, md5 cannot be used with the db_user_namespace feature. 但是,md5不能与db_user_namespace功能一起使用。 If the connection is protected by SSL encryption then password can be used safely (though SSL certificate authentication might be a better choice if one is depending on using SSL). 如果连接受SSL加密保护,则可以安全地使用密码(但如果依赖于使用SSL,则SSL证书身份验证可能是更好的选择)。

Sample location for pg_hba.conf : pg_hba.conf示例位置:
/etc/postgresql/9.1/main/pg_hba.conf


#3楼

I had the same problem. 我有同样的问题。

The solution from depa is absolutely correct. 来自depa的解决方案绝对正确。

Just make sure that u have a user configured to use PostgreSQL. 只需确保您已将用户配置为使用PostgreSQL。

Check the file: 检查文件:

$ ls /etc/postgresql/9.1/main/pg_hba.conf -l

The permission of this file should be given to the user you have registered your psql with. 应该将此文件的权限授予您已注册psql的用户。

Further. 进一步。 If you are good till now.. 如果你现在好,..

Update as per @depa's instructions. 根据@depa的说明更新。

ie

$ sudo nano /etc/postgresql/9.1/main/pg_hba.conf

and then make changes. 然后进行更改。


#4楼

After installing Postgresql I did the below steps. 安装Postgresql后,我做了以下步骤。

  1. open the file pg_hba.conf for Ubuntu it will be in /etc/postgresql/9.x/main and change this line: 打开Ubuntu的文件pg_hba.conf ,它将在/etc/postgresql/9.x/main并更改此行:
local   all             postgres                                peer

to

local   all             postgres                                trust
  1. Restart the server 重启服务器
 sudo service postgresql restart 
  1. Login into psql and set your password 登录psql并设置密码

psql -U postgres psql -U postgres

ALTER USER postgres with password 'your-pass';
  1. Finally change the pg_hba.conf from 最后更改pg_hba.conf
local   all             postgres                                trust

to

local   all             postgres                                md5

After restarting the postgresql server, you can access it with your own password 重新启动postgresql服务器后,您可以使用自己的密码访问它

Authentication methods details: 验证方法细节:

trust - anyone who can connect to the server is authorized to access the database 信任 - 任何可以连接到服务器的人都有权访问数据库

peer - use client's operating system user name as database user name to access it. peer - 使用客户端的操作系统用户名作为数据库用户名来访问它。

md5 - password-base authentication md5 - 基于密码的身份验证

for further reference check here 有关进一步参考, 请点击此


#5楼

If you connect over localhost (127.0.0.1) you shouldn't experience that particular issue. 如果您通过localhost(127.0.0.1)连接,则不应遇到该特定问题。 I wouldn't muck much with the pg_hba.conf but instead I would adjust your connection string: 我不会吝啬pg_hba.conf但我会调整你的连接字符串:

psql -U someuser -h 127.0.0.1 database

where someuser is your user you're connecting as and database is the database your user has permission to connect to. 其中某个用户是您正在连接的用户,而数据库是您的用户有权连接的数据库。

Here is what I do on Debian to setup postgres: 这是我在Debian上设置postgres的方法:

http://www.postgresql.org/download/linux/debian/  (Wheezy 7.x)as root …root@www0:~# echo "deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main" >> /etc/apt/sources.listroot@www0:~# wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -root@www0:~# apt-get updateroot@www0:~# apt-get install postgresql-9.4        root@www0:~# su - postgres postgres@www0:~$ createuser --interactive -P someuserEnter password for new role:Enter it again:Shall the new role be a superuser? (y/n) nShall the new role be allowed to create databases? (y/n) yShall the new role be allowed to create more new roles? (y/n) npostgres@www0:~$ createdb -O someuser databasepostgres@www0:~$ psql -U someuser -h 127.0.0.1 database

Enjoy! 请享用!


#6楼

以下命令对我有用:

psql -d myDb -U username -W

获取错误:当试图让pgsql使用rails时,用户“postgres”的对等身份验证失败相关推荐

  1. 身份验证错误错误指定的句柄无效_基于 Web 端的人脸识别身份验证「实践」

    作者:沫沫 政采云前端团队 转发链接:https://mp.weixin.qq.com/s/fRDpXixnLIy9c0Uh2tMezQ 前言 近些年来,随着生物识别技术的逐渐成熟,基于深度学习的人脸 ...

  2. 验证远程计算机是证书发生错误,win7电脑远程桌面连接提示发生身份验证失败错误 代码0X80070005-♚付涛纪实阁♚...

    问题背景 可能是看着电脑硬盘一下子被撑的太爆,有些看不下去,所以索性对电脑C盘进行了一次深度的瘦身,最后终于成功将C盘由原来剩余的24.5G,变成了现在瘦身之后的64.9G可用空间,足足删除了近40G ...

  3. 假设某系统的登录账号是“Admin“,密码是“p888888“;编程实现要求用户输入账号和密码,当验证通过时显示“登录成功”,当验证失败时显示“账号或密码错误”

    #define _CRT_SECURE_NO_WARNINGS#include<stdio.h> #include<string.h> int main() {char acc ...

  4. 饥荒服务器身份验证错误,饥荒服务器身份验证失败 | 手游网游页游攻略大全

    发布时间:2015-09-22 昨天蚕豆网小编给大家带来了iOS体验试玩版给大家下载试玩,虽然有时候游戏进不去,但最后还是能快乐的进入游戏玩耍的.而今天早上,小编再次准备进入的时候发现了一些 ... ...

  5. linux php soapclient 认证,php – 401身份验证SoapClient尝试获取模式文...

    我的应用程序通常连接到第三方服务器以通过SOAP / WSDL获取数据: $this->soap_client = new SoapClient("https://[the-domai ...

  6. 远程桌面连接“发生身份验证错误。 无法连接到本地安全机构”解决方法

    2019独角兽企业重金招聘Python工程师标准>>> 症状 当试图建立远程桌面连接使用远程桌面服务器运行的是 Windows Server 2008 R2 为远程桌面客户端 (ms ...

  7. 无法在Web服务器上启动调试。与Web服务器通信时出现身份验证错误

    使用Visual Studio 2005(Visual Studio 2008亦存在此问题)调试设置了主机头的网站时出现如下错误信息: --------- Microsoft Visual Studi ...

  8. Asp.Net MVC及Web API添加身份验证及错误处理的过滤器

    先说身份验证的问题.无论是mvc还是api都有一个安全性的问题,未通过身份验证的人能不能访问的问题.我们新一个空项目时,默认是没有身份验证的,除非你在控制器类或者方法上面加上Authorize属性才会 ...

  9. linux用户登录身份验证错误,启动 WLS 时的身份验证错误(解决linux下问题)

    The WebLogic Server did not start up properly. Reason: weblogic.security.SecurityInitializationExcep ...

最新文章

  1. 【C语言学习趣事】_GCC源代码分析_2_assert.h
  2. Java NIO学习系列一:Buffer
  3. 如何看待Scrum Sprint Backlog冻结和变化?
  4. 02、如何进行网站性能优化或怎么加快页面的加载速度
  5. 《Agile Impressions》作者问答录
  6. 微信小程序scroll-view去掉滚动条
  7. Java高级程序猿技术积累
  8. kubernetes Istio是什么
  9. ROS - 科大讯飞语音包使用
  10. Python抠图程序源码
  11. httpclient 下载文件
  12. java中数组集合存放位置_java中数组以及集合
  13. VMware Workstation虚拟机安装及虚拟机搭建(内有虚拟机安装包及序列号和系统镜像)...
  14. 创建一个背景色为蓝色的Pygame窗口
  15. 基于Java毕业设计新疆旅游专列订票系统源码+系统+mysql+lw文档+部署软件
  16. 《途客圈创业记:不疯魔,不成活》一一1.2 Alex和剑桥MBA
  17. C# 数据库介绍及基本操作
  18. 【python学习笔记】自动抓取雅虎新闻的内容
  19. 微信公众号开发---机器人
  20. 【ZooKeeper】大数据之分布式协调神器:ZooKeeper选举

热门文章

  1. Binder相关面试总结(四):一次Binder通信的基本流程是什么样?
  2. Linux的IPC机制(三):Binder
  3. 几个WIindows函数。坐标转换
  4. 算法------------存在重复元素 II(Java 版本)
  5. Java多线程开发之------多线程等待
  6. Android stadio Switch repository Android stadio切换仓库
  7. Android中shape属性详解
  8. 字符串比较--小问题大智慧
  9. mysql search yum_centos7通过yum安装mysql的方法
  10. python opencv 腐蚀_opencv 图像的腐蚀(erode)和膨胀(dilate) 开运算以及闭运算