Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active July 7, 2016 05:49
Show Gist options
  • Save nepsilon/ced70a190621aa2d1dc3 to your computer and use it in GitHub Desktop.
Save nepsilon/ced70a190621aa2d1dc3 to your computer and use it in GitHub Desktop.
PostgreSQL password-less authentication — First published in fullweb.io issue #40

PostgreSQL password-less authentication

Contributed by Fabien Loudet, Linux SysAdmin at Rosetta Stone

The format to use for each line in the file:

hostname:port:database:username:password

Only the owner of the file should have read and write access to it:

chmod 0600 ~/.pgpass

Enjoy passwordless authentication! As long as the connection parameters are properly set in the .pgpass file, you should not be prompted for password

psql -h hostname -U username -h hostname -d database

BONUS: Use password-less authentication on backup scripts with pg_dump and its -w option:

pg_dump -h hostname -U username -d database -w > dump.bak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment