Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackie-do/7f90429ebdab1f9874f5c71d513d5a3a to your computer and use it in GitHub Desktop.
Save jackie-do/7f90429ebdab1f9874f5c71d513d5a3a to your computer and use it in GitHub Desktop.
Set up authentication methods for postgresql users
  1. Go to config directory
 cd /etc/postgresql/<postgresql_version>/main
  1. Open and update file "pg_hba.conf" to dismiss all authentications for "postgres" user (normally line 85)
  • Before updating
 local   all             postgres                                peer
  • After updating
local   all             postgres                                trust
  1. Restart Postgresql service to apply new configuration
sudo service postgresql restart
  1. Login to postgresql with user "postgres" (without any authentications)
psql -U postgres
  1. Change password of this postgresql user
ALTER USER postgres WITH PASSWORD '<your password>';
  1. Reupdate file "pg_hba.conf" to apply password authentication for "postgres" user
  • Before updating
 local   all             postgres                                trust
  • After updating
local   all             postgres                                md5
  1. Restart Postgresql service to apply new configuration
sudo service postgresql restart
  1. Login to postgresql with user "postgres" (require password)
psql -U postgres
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment