Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

Empowering you to understand your world

PostgreSQL Tutorial: Change PostgreSQL Authentication Method From ‘peer’ to ‘md5’

PostgreSQL configuration file
PostgreSQL configuration file pg_hba.conf.

By Nicholas Brown.

If you want to log into your PostgreSQL database by entering a password, you can do so by changing the authentication method from ‘peer‘ to ‘md5‘. There is also the ‘password’ authentication method, but that sends the password in clear text, so I won’t recommend that. Both the md5 and password authentication methods prompt you for a password on login.

If you are just setting up a new PostgreSQL installation which is not yet exposed to any networks, you can temporarily change the authentication method for your respective username in the pg_hba.conf file to ‘trust’, then restart PostgreSQL with the following command if you’re on Ubuntu, and then change the authentication method back to md5 right after:

Find that PostgreSQL configuration file by typing: ‘sudo nano /etc/postgresql/14/main/pg_hba.conf‘. look for the user ‘postgres’ in white and look to the right for the ‘md5’. That’s where you set the authentication method for that PostgreSQL user.

PostgreSQL configuration file pg_hba.conf. PostgreSQL configuration file pg_hba.conf. Click the image to see a larger, clearer version of it
sudo service postgresql restart

Now you can login by typing:

psql -U postgres

It should let you in without a password prompt this time (not after you’re finished setting it up). Type ‘\password’ and then enter your desired password. Ensure that it is strong and contains a combination of numbers, letters, and symbols.

Now you must change the PostgreSQL authentication method back to md5, and it will prompt you for your password when you want to log into PostgreSQL from now on. Don’t leave it as ‘trust’, because anybody will be able to access your databases.

Leave a Reply

Subscribe to our newsletter
Get notified when new content is published