This article discusses how to create an encrypted password and how to assign that encrypted password to a user during the CREATE ROLE statement.
Creating a user from the PSQL prompt may result in logging the password in plain text to the pg_log file.
echo -n ${USERPASSWORD}${USERNAME} | md5sum
CREATE ROLE test WITH PASSWORD 'md5<output_from_step_2>'
It is very important to add the option -n to the command echo, otherwise, this won't work.
Refer below for a working example of the procedure
In this example, we use password pivotal for user test.
[gpadmin@mdw2 boc_4361_-1]$ echo -n pivotaltest | md5sum 562cbe7b006b198b75ca1858da667e6b - [gpadmin@mdw2 boc_4361_-1]$ psql psql (8.2.15) Type "help" for help.
gpadmin=# alter role test password 'md5562cbe7b006b198b75ca1858da667e6b'; ALTER ROLE
[gpadmin@mdw2 boc_4361_-1]$ psql -U test -h 127.0.0.1 gpadmin Password for user test: psql (8.2.15) Type "help" for help. gpadmin=>
[gpadmin@mdw2 boc_4361_-1]$ psql -U test -h 127.0.0.1 gpadmin Password for user test: psql (8.2.15) Type "help" for help. gpadmin=>
Review the article Avoid Printing Sensitive Messages like Password to Master Logs for another security method that avoids printing a plain text password to the log file.