This guide details the steps to install PostgreSQL 17 on Ubuntu 24.04 and configure it for remote access using password authentication (scram-sha-256
).
sudo apt update
sudo apt install -y postgresql-common
sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
Note: Press Enter
when prompted to proceed.
sudo apt update
sudo apt install -y postgresql
sudo systemctl status postgresql
postgres
Usersudo -u postgres psql
ALTER USER postgres WITH ENCRYPTED PASSWORD 'your_strong_password';
\q
pg_hba.conf
:sudo sed -i '/^local\s\+all\s\+postgres\s\+/s/peer/scram-sha-256/' /etc/postgresql/17/main/pg_hba.conf
echo "host all all 0.0.0.0/0 scram-sha-256" | sudo tee -a /etc/postgresql/17/main/pg_hba.conf
postgresql.conf
to Allow Remote Connections:sudo nano /etc/postgresql/17/main/postgresql.conf
Change the following line:
listen_addresses = '*'
sudo systemctl restart postgresql
Ensure port 5432
is open and test with:
psql -h <your_server_ip> -U postgres -d postgres -W
'your_strong_password'
with a secure password.5432
.