Centos

無法設置 postgres 使用者密碼

  • April 26, 2014

嘗試使用以下指南在 CentOS 6.5 上使用 Ruby on Rails 和 Nginx 安裝 PostgreSQL:http: //karolgalanciak.com/blog/2013/07/19/centos-6-4-server-setup-with-ruby-on- rails-nginx-and-postgresql/

安裝後我去配置使用者,sudo su postgres然後發出命令psql。當我這樣做時,我收到以下錯誤:

could not change directory to "/root": Permission denied
psql (9.3.4)

忽略這一點,我發出了命令:

alter user postgres with password 'postgres-user-password';

然後我去把 auth 方法改成 md5 dy 做:

sudo vi /var/lib/pgsql/9.3/data/pg_hba.conf

當我這樣做時,我會看到提示:

[sudo] password for postgres:

無論我輸入什麼密碼,Sorry, try again.即使密碼正是我剛剛設置的密碼,我也會被告知。

嘗試按照 user716468 的這篇文章中的說明進行操作,但沒有運氣: 新安裝後 postgres 的預設超級使用者使用者名/密碼是什麼?

當我這樣做時,sudo -u postgres psql postgres我被告知:

postgres is not in the sudoers file.  This incident will be reported.
You have new mail in /var/spool/mail/root

這裡有什麼問題?

首先,在使用 sudo 時,請始終使用 -l 或直接使用 - *。*例如,“ sudo su - postgres”不是“ sudo su postgres”。這可確保您正確選擇目標使用者環境。

聽起來您正在使用 sudo 作為 root 使用者。這是不必要的。root 使用者已經擁有所需的權限。

如果您希望使用者使用 sudo,那麼您需要在 /etc/sudoers. 由於 postgres accoutn 是一個服務帳戶,因此最好不要為 postgres 創建 sudoers 條目。最好僅以 root 身份或從“普通”帳戶進行 sudo 操作。

引用自:https://serverfault.com/questions/591450