Install Postgresql 13 on RHEL 8. Configure scram-sha-256 password authentication.

Himanshu Pratap
2 min readApr 13, 2022
  1. Steps Summary
    a. install postgresql-server
    b. initialize database
    c. set password for postgres os user
    d. enable and run postgresql service
    e. modify postgresql.conf file ( listen_address and password_encryption)
    f. login to postgresql database using peer authentication and modify postgres db user password
    g. modify pg_hba.conf file to set authnetication to scram-sha-256
    h. restart postgresql service.
  2. Install postgresql 13
# dnf module list | grep postgres
# dnf module install postgresql:13

2. Initialize database

# which postgresql-setup
# postgresql-setup --initdb

3. Change password for os user postgres auto created after installing postgresql

# passwd postgres

4. Enable and start postgresql service

# systemctl enable postgresql
# systemctl start postgresql
# systemctl status postgresql

5. Modify postgresql.conf file

#vim /var/lib/pgsql/data/postgresql.conflisten_addresses = '*'
password_encryption = scram-sha-256

6. login to postgres database using peer authentication.

# su - postgres
# psql
postgres=# \conninfo

7. Change postgres database user password and password encryption method

postgres=# \password
postgres=# set password_encryption TO 'scram-sha-256';

8. Change authentication type to scram-sha-256 in pg_hba.conf file

# cd /var/lib/pgsql/data
# vim pg_hba.conf
# TYPE DATABASE USER ADDRESS METHOD# "local" is for Unix domain socket connections only
local all all scram-sha-256
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all scram-sha-256
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256

9. Restart postgresql service and login using password authentication

# systemctl restart postgresql
$ psql -U postgres -d postgres

--

--