Claus-Theodor Riegg
7 years
Claus-Theodor Riegg
7 years
Stefan Langenmaier
1 year
Andreas Vöst
3 months
Claus-Theodor Riegg
4 years
Andreas Vöst
4 months
Andreas Vöst
5 months
Kim Klotz
5 months
Claus-Theodor Riegg
8 years

HowTo: Create scram-sha-256 password hash for use with postgres

Posted . Visible to the public.

If you need to pre-generate a scram-sha256 password hash for use with postgres, e.g. for using it with config management like puppet, pre-generating the password hash can be done in a small oneliner on any machine that has postgres installed:

$ createuser -e dummy --pwprompt
Enter password for new role: 
Enter it again: 
SELECT pg_catalog.set_config('search_path', '', false);
CREATE ROLE dummyuser PASSWORD 'SCRAM-SHA-256$4096:QJQsradJegC1DjzhWFAUEw==$l60VVp5kOM1YzLBqv7mRxZ7A0J31dQgV69Ugzkj/Frc=:ZhqSB6yXeV+Cf+5Q32fylOoukYJrutprcDmzYwM3pTY=' NOSUPERUSER NOCREATEDB NOCREATEROLE INHERIT LOGIN;

and the salted password hash can be retrieved between the single quotes after PASSWORD.

This will not actually create a user on your postgres cluster. The -e option means echo.

Emma Heinle
Last edit
Simon Hofmann
License
Source code in this card is licensed under the MIT License.