1

I am creating a role in postgresql. The documentation gives me the following example with clear-text password:

CREATE ROLE foo WITH LOGIN PASSWORD 'secret'

My task is to use MD5 instead of a clear-text password because it is not secure enough. However, the documentation merely mentioned the possibility to use md5 instead of a password, without giving any example code. I wonder how could I re-write the code above to implement MD5? Thank you in advance!

1
  • Note that the password is stored in md5 (or SCRAM) even if you specified it in plain text. Commented Apr 28, 2022 at 14:40

1 Answer 1

2

To change the authentication method:

  1. Open a terminal window
    
  2. Change into the postgres bin directory  
    

Example: cd /usr/local/pgsql/bin

Note: Depending on your install environment the path to the bin directory may vary.

  1. Type su – postgres and press Enter.  This will change the logged in to the postgres user.
    
  2. From the bin directory type ./psql
    
  3. Type ALTER USER postgres password 'your shell account postgres password'; and press Enter.  ALTER ROLE should be displayed.
    
  4. Type \q and press Enter
    
  5. Type vi /path to data directory/pg_hba.conf and press Enter
    
  6. Modify the line at the bottom of the config file to resemble one of these examples.
    

Note: You will probably only have to change the word trust to md5. The line or lines should already exist.

host all postgres your.ip your.subnet md5

host all all your.ip your.subnet md5

Note: If you are using vi as the editor press i to insert text

  1. Save the changes
    

Note: If you are using vi as the editor press i to insert then press :wq! to save the changes.

  1. From the postgres bin directory type./pg_ctl restart -D /usr/local/pgsql/data and press Enter
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your help! Is it possible to conduct it within pgAdmin?
yes it is possible
How to do that on pgadmin?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.