Enabling Postgresql installed on EC2, to access anyone remotely

PHOTO EMBED

Mon Feb 21 2022 07:37:25 GMT+0000 (Coordinated Universal Time)

Saved by @irfan309 #psql #database-creation #login-to-database #user-creation #grant-privileges-to-user #login-to-db-as-create-user #user-creation-with-password

#opening postgresql config file to enabling from local to everyone
#firt open this file on machine to make changes
sudo vi /etc/postgresql/12/main/postgresql.conf
#to quickly search on editor easily type as '/' & the type word to search 'listen_address'
/listen_address
#by default listen_addresses = 'localhost'
#so we are changing 'localhost' to '*' it means by placing the '*' any one can access.
listen_addresses = '*'
#now change one more config file called 'pg_hba.config' to give access, so open the file as below
sudo vi /etc/postgresql/12/main/pg_hba.conf

# add the line end of the file 
host    all             all             0.0.0.0/0               md5

#for above mentioned line reference in  detailed 
https://www.postgresql.org/docs/9.1/auth-pg-hba-conf.html

# now restart the postgres so it will restart the service and apply the changes internally
# first check the status 
 sudo service postgresql status
 
# now restart the postgresql service
 sudo service postgresql status

content_copyCOPY