Mosquitto failing to authenticate - raspberry-pi

I genuinely have no idea what I'm doing wrong. But no matter how many different ways I try to set a username and password for my mosquitto server, the connection is not authorized.
This seems like such a simple process I'm not even sure what to ask. But here's the tutorial I followed: http://www.steves-internet-guide.com/mqtt-username-password-example/
I tried both methods, and I know for a fact I'm typing my username and password in right: mosquitto_sub -d -t MessageBoard -u ServerPi -p *******, but all I receive in return is:
Error: Connection refused
Here is my config:
listener 1883
persistence true
allow_anonymous false
password_file /etc/mosquitto/passwd
Edit: The actual command I used a capital -P. For some reason when using the correct username and password it’s still not authorizing me.

The password option is -P, not -p. -p means port.
"Error: Connection refused" means that TCP indicated nothing was listening on the port, which can be caused by the broker not running, the broker not listening on that port, or sometimes a firewall. You'd see an "unauthorized" error if you gave the wrong password, but you're not getting that far because you're using the wrong option, causing mosquitto_sub to try to connect to the wrong port.
Unless your password is all numbers I'm surprised and disappointed that mosquitto_sub isn't warning you that the port number is invalid.
For more information on mosquitto_sub, please see its man page.

Related

How to use port 5434 on main server for postgresql streaming replication

I am trying to do streaming replication between two postgresql servers. Main server is listening on port 5434 and I have to keep it so. When I run "pg_basebackup -h (main server ip) -D /var/lib/postgresql/13/main/ -U replicator -P -v -R -X stream -C -S slaveslot1" on replica server I get the follwing error:
"pg_basebackup: error: could not connect to server: Connection refused. Is the server running on host (main server ip) and accepting TCP/IP connections on port 5432?"
Almost all similar questions that I found in the web are dealing with some other problems as their main server is already using port 5432.
So, could you please let me know how I can keep port 5434 on main server and still run the above command for replication? Thanks in advance!
I was expecting the command to run normally and ask me for password.
I have changed the port to 5432 and in that case it works, so the command itself doesn't have mistakes in it.
But I don't know what/how I can do it if I am keeping port 5434.
You can either use the -p option of pg_basebackup, or you can set the PGPORT environment variable, or you can use the -d option with a connection string that contains port=5434.

Postgres login via localhost timeout

I've installed Postgres.app and modified the port number to 5466, I've enabled listen_addresses='*'.
I've setup 'trust' in pg_hba.conf.
I can connect through the socket via psql. However, psql -h localhost -p 5466 fails and returns *"server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request."
Port 5466 is mapped to postgresql.
Any help as to why I can connect to the socket, but not to localhost would be appreciated. If i connect on another port an error is returned instantly telling me there is no server there, but when I connect on the correct port the connection hangs and returns the error above.
The problem was a program to monitor internet traffic blocked all ports other than 80: https://github.com/PostgresApp/PostgresApp/issues/169

Can't connect to pgpool

I'm playing around pgpool2.
I'm connecting to postgresql which is running on port 5432 with command psql -U postgres -p 5432 and it's connecting normally.
When I'm connecting to pgpool2 running on 9999 port with command psql -U postgres -p 9999 - it returns back dialog like:
psql: root#master:/linux/path#
What I'm doing wrong? Is there way to connect to pgpool using psql?
I cannot connect to it from application also.
UPD I've got following error pool_do_auth: maybe protocol version mismatch (current version 3)
Solved : Problem was in pgpool auth on backends. Editing pg_hba.conf fixed problem.
This error message and behavior are because of a problem with pgpool authenticating to postgres, not with you authenticating to pgpool as you might suspect. If you check the postgres logs, it will tell you which line in your postgres pg_hba.conf is being rejected.
However, since (IIRC) pgpool cannot do peer authentication, it is probably this one, which says that all local (unix socket) connections will be authenticated by pretending the system username is the postgres username:
local all all peer
You want to change that to:
local all all trust
At least to make things work. However, you will lose some security this way. However, if all your users (that can access the unix socket) are trusted, this is okayish.

pgAdmin and PostgreSQL: can't connect to server

I just installed PostgreSQL on Snow Leopard and can't connect to the database server via pgAdmin 3.
I'm on my local machine, however I keep getting this error:
Could not connect to server: connection refused. Is the server running on host "localhost" (127.0.0.1) and accepting TCP/IP connections on port 5423?
I'm a bit of a noob when it comes to Postgres, so I'm not really sure what the problem is.
I can, however, log in through the command line, via psql -U postgres, and start and stop the server successfully.
Any help would be much appreciated.
The error message pointed out that you tried to connect to server on port 5423. However, postgres server listens on 5432 by default.
From your above comment (SHOW port; gives me "5432"), I think you need to change the port to 5432!
UPDATE: Tuan Dang spotted it. I'll leave this answer in place in case it helps someone else for whom the issue isn't quite the same.
Since you can connect via the command line, run:
SHOW port;
from psql. You'll probably see that the port is not 5432. You need to connect to the port PostgreSQL is actually running on from your application.
It's also possible that it just isn't listening on TCP/IP. Run:
SHOW listen_addresses;
to see what it's listening for.
The reason you can connect via the command line is likely to be because the command line psql you're using is connecting over a unix socket (since you didn't specify a host) and your app is connecting via tcp/ip.

Cannot connect to postgres from remote host

I have a database server (192.168.1.50) running postgres. I have created a database named "testdb" and a user "testuser" with password "testuserpw".
Locally, I can connect to the db using:
psql -d testdb -U testuser
When I issue the command from another host (192.168.1.60):
psql -h 192.168.1.50 -d testdb -U testuser
I have the error:
psql: could not connect to server: Connection refused
Is the server running on host "192.168.1.50" and accepting
TCP/IP connections on port 5432?
Any idea ?
Check the setting of listen_addresses in your postgresql.conf file. Many distributions make it default to 127.0.0.1, i.e. listen only to connections coming in from localhost. It should be set to '*' to listen for connections on all interfaces.
If you are still having trouble, use lsof to see what network sockets the postgres process is listening on.
On Ubuntu, I noticed that remote access at some point stopped working (currently using 9.1.9). The reason is, that postgres is no longer started with the -i switch [1] so no matter what you configure for listen_addresses, it will be ignored.
Fortunately, adding the following line to /etc/environment solves the problem after logging out and in again (or reboot):
PGOPTIONS="-i"
See [2] for more options. Note, that adding this to /etc/postgresql/9.1/main/environment did NOT work for me.
Now, when doing nmap ip-of-my-remote-server I finally get this again:
5432/tcp open postgresql
Yay!
[1] http://www.postgresql.org/docs/9.1/static/runtime-config-short.html
[2] http://www.postgresql.org/docs/9.1/static/libpq-envars.html
Is the firewall letting the connections through? Or, check if pg_hba.conf allows connecting from addresses other than localhost.
The listen_address configvar in postgresql.conf is not the only way to get postgres to listen on the non-local IP-address (or addresses).
Use option "-o -h *" if you start postgres from pg_ctl, otherwise do add "-h" "*" to the postgres command line, like e.g.
/usr/local/pgsql/bin/postgres -D /pg/data "-h" "*"
Of course /pg/data must be changed to your current datapath.
This is especially useful when experimenting.
I came across the same problem as yours, and my source of problem is the firewall settings.
If you're using Ubuntu, print your firewall status:
sudo ufw status verbose
It may looks like this:
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
...
The default rule of incoming connection is "deny", so you need to specify the "allow"ed port.
type:
sudo ufw allow 5432/tcp
reference:
https://www.vultr.com/docs/how-to-configure-ufw-firewall-on-ubuntu-14-04
Connection refused (0x0000274D/10061) i fixed here with:
Open the terminal and type:
VIM /var/lib/pgsql/data/postgresql.conf
Edit the "listen_adresses", it should be set to '*'
After this, rest it on terminal:
/scripts/restartsrv_postgres