Lab: unable to edit pg_hba.conf properly for troubleshoot developement environment

HI,

I am working on Linux basic linux course last Lab( [troubleshoot development environment]). I have tried updating this file using Vi editor but it always shows file not updated correctly. i have ran Cat command to check content in file. I am pasting it here. i know i have to add host all all 0.0.0.0/0 md5 to the end of file to make sure web server connects to DB server. can someone please help? @Ayman @vijin.palazhi

# PostgreSQL Client Authentication Configuration File
# ===================================================
#
# Refer to the "Client Authentication" section in the PostgreSQL
# documentation for a complete description of this file.  A short
# synopsis follows.
#
# This file controls: which hosts are allowed to connect, how clients
# are authenticated, which PostgreSQL user names they can use, which
# databases they can access.  Records take one of these forms:
#
# local      DATABASE  USER  METHOD  [OPTIONS]
# host       DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
# hostssl    DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
# hostnossl  DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
#
# (The uppercase items must be replaced by actual values.)
#
# The first field is the connection type: "local" is a Unix-domain
# socket, "host" is either a plain or SSL-encrypted TCP/IP socket,
# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a
# plain TCP/IP socket.
#
# DATABASE can be "all", "sameuser", "samerole", "replication", a
# database name, or a comma-separated list thereof. The "all"
# keyword does not match "replication". Access to replication
# must be enabled in a separate record (see example below).
#
# USER can be "all", a user name, a group name prefixed with "+", or a
# comma-separated list thereof.  In both the DATABASE and USER fields
# you can also write a file name prefixed with "@" to include names
# from a separate file.
#
# ADDRESS specifies the set of hosts the record matches.  It can be a
# host name, or it is made up of an IP address and a CIDR mask that is
# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
# specifies the number of significant bits in the mask.  A host name
# that starts with a dot (.) matches a suffix of the actual host name.
# Alternatively, you can write an IP address and netmask in separate
# columns to specify the set of hosts.  Instead of a CIDR-address, you
# can write "samehost" to match any of the server's own IP addresses,
# or "samenet" to match any address in any subnet that the server is
# directly connected to.
#
# METHOD can be "trust", "reject", "md5", "password", "scram-sha-256",
# "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert".
# Note that "password" sends passwords in clear text; "md5" or
# "scram-sha-256" are preferred since they send encrypted passwords.
#
# OPTIONS are a set of options for the authentication in the format
# NAME=VALUE.  The available options depend on the different
# authentication methods -- refer to the "Client Authentication"
# section in the documentation for a list of which options are
# available for which authentication methods.
#
# Database and user names containing spaces, commas, quotes and other
# special characters must be quoted.  Quoting one of the keywords
# "all", "sameuser", "samerole" or "replication" makes the name lose
# its special character, and just match a database or username with
# that name.
#
# This file is read on server startup and when the server receives a
# SIGHUP signal.  If you edit the file on a running system, you have to
# SIGHUP the server for the changes to take effect, run "pg_ctl reload",
# or execute "SELECT pg_reload_conf()".
#
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records.  In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.




# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:


host    all             all             0.0.0.0/0               md5
Host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.

host    all             all             0.0.0.0/0               md5
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

Hello, bhvk49
You won’t able to edit page from sudo or root user?

1 Like

I have tried using sudo vi /etc/postgresql/10/main/pg_hba.conf. Still not working

1 Like

Can you paste here o/p of error?

@Tej-Singh-Rana on clicking check button for this question, it says “pg_hba.conf” file not updated correctly.
So after that i checked the content of file using cat command and i have pasted the content of file in question itself

So it’s working now?

No , its not working. Can you let me know where do i need to put that exactly in a file or can you share the file? i am also facing issue navigating through file.

Which lab number it is?
Got it.

it is the last lab in linux basic course . “Troubleshoot development environmet”

Issue in the file, when you will run ls -l command :
ls -l /etc/postgresql/10/main/pg_hba.conf
You will see there is no permission to write for other users into the file so you need to change the permission of the file.
Do with the command:
sudo chmod 777 /etc/postgresql/10/main/pg_hba.conf
after edit the file change again the file permission
sudo chmod 644 /etc/postgresql/10/main/pg_hba.conf
After changes in the configuration file, make sure restart the postgresql service

okay. That explains correctly. Thanks

but no matter what i try it always says that pg_hba.conf not updated correctly. I have again ran cat command and i do see that changes are made but its still not proceeding. Below is the conctent of the file

# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     peer
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.



host    all             all             0.0.0.0/0               md5
local   replication     all                                     peer
host    replication     all             127.0.0.1/32            md5
host    replication     all             ::1/128                 md5

Where you will see this message?

i see that message on Right side.

I am able to proceed with other question and able to complete the lab successfully. i believe that file has been changed successfully but there is error in validation to check for this question.

I am even able to access project mercury on my browser.

Thanks

Hi @bhvk49 & @Tej-Singh-Rana,

I am also facing issues with editing the pg_hba.conf file. It doesn’t seem to matter what I do. I have changed the permissions and the editor just does not seem to work. For example, when I go into insert mode with i @ the end of the file and attempt to type anything the last line gets deleted and replaced with the letter B and when I exit command mode and try to undo the last action with u, the editor seems to not know what to do…

Also, if I attempt to scroll down in insert mode the same thing happens (see scroll-i-png).

I’m not sure what to do. This happened to me yesterday as well.

I am going to attempt to move forward with the other challenges in the lab.

Cheers:-)

1 Like

Hi @juliettet,

Yeah, actually i don’t understand this. Every other vi commands and file edits for the labs worked perfectly.Only in this lab it behaves strange.

One thing i have noticed is that, it does get saved after changes, it just doesn’t reflect when we hit check button. Mine next question and challenges worked fine and i was able to access project mercury perfectly.

I do see that line is still not added in your file. i believer it might create issue in upcoming question. You may copy content of my file i have pasted here :slight_smile:

what i have done is 1. Opened that file using vi command 2. Haven’t gone to the end of the file(just gone to the last third line). 3. Entered insert mode(it’s quite challenging as there issue in this). 4. It might add some letter, delete that letter and start typing the content manually(do not copy paste). 5. hit ‘Esc’ key and type :wq(to save the file)

Hope this helps

1 Like

Hi @bhvk49,

Thank you for responding. I know…It is strange. Hmmm…

Every other vi commands and file edits for the labs worked perfectly.Only in this lab it behaves strange.

Yep. Same here:-)

I do see that line is still not added in your file

I was trying to add it at the end of the file, but it wouldn’t let me. I am going to try your suggestion to copy and paste what you have (if it will let me). Wish me luck!!

Thank you again! :grinning:

1 Like

Okay @juliettet I will look into it. Thanks for reporting.

1 Like

Thank you @Tej-Singh-Rana. I gave this exercise another go yesterday and the same thing happened.

I thought I was doing wrong when i saw characters appearing. Looks like many actually faced this issue.

1 Like

They fixed the issue and I also checked. You can try now. Report it if you face again. Thanks

2 Likes