Bootstrap FreeKB - Postgres (SQL) - passwordless authentication using the hidden .pgpass file
Postgres (SQL) - passwordless authentication using the hidden .pgpass file

Updated:   |  Postgres (SQL) articles

Create the hidden .pgpass file is your users home directory.

touch $HOME/.pgpass

 

Update the file so that only the owner can read and write to the file.

chmod 0600 $HOME/.pgpass

 

Add line in the file in this format.

hostname:port:database:username:password

 

For example.

localhost:5432:mydb:johndoe:itsasecret

 

You should now be able to connect to Postgres without a password.

~]$ psql --username johndoe --dbname mydb --command "\list"
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
 mydb      | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +
           |          |          |             |             | postgres=CTc/postgres+
           |          |          |             |             | ec2user=CTc/postgres
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 4fd71a in the box below so that we can be sure you are a human.