Administer postgres from PGAdmin on remote mac using ssh tunnel - ssh

I've got PostgreSQL installed on a Ubuntu server and I'm trying to connect to that server using PGAdmin on a remote macbook.
I've created an ssh tunnel -
macbook:~postgres$ ssh -L 5423:localhost:5432 postgres#mydomain.com
And I can connect using psql on the macbook as expected -
macbook:~ me$ psql -U postgres -p 5423 -h localhost
...
postgres=#
In the 'New Server Registration' window on PGAdminIII I'm entering the following credentials
Name - MyServer
Host - localhost
Port - 5423
Maintenance DB - postgres
Username - postgres
Password - <remote_postgres_password>
However the connection fails -
Error connecting to the server: FATAL: password authentication failed for user "postgres"
Not sure what's going on here, these seem to be the same credentials I've used for psql.

In your server, choose md5 as password authentication on pg_hba.conf file. For example:
host all all 12.34.67.89 255.255.255.255 md5
While 12.34.67.89 is your remote ip. I'm facing the same problem last week. Hope that helps.

Related

how to check ssh tunnel opened by a Dbeaver client for a pg_dump task?

i actually use a dbeaver client to connect to a remote Postgres database.
dbeaver client use a bastion, by creating a ssh tunnel between localhost and bastion
(and then, bastion is connected to the database).
We have something like that
localhost (dBeaver) --> bastion --> postgres database
to make a backup of my database, dbeaver client use a command like :
pg_dump --verbose --host=127.0.0.1 --port=59914 --username=my-user --format=c -t public.dashboard my-database > /dump.sql
so, i deduce that dbeaver created a tunnel between my localhost 55914 to the remote port of the postgres database (5432)
All is well and works perfectly, but i'd like to understand how dbeaver created the ssh tunnel.
How can we check in Linux that it exist an opened tunnel from my 59914 local port to the remote postgres database, using interdemediary bastion machine ?
What is the command line to check that ?

Double tunnel hop ssh

I'm using WinSSHTerm to connect to a proxy, from which I then connect to a server hosting a data warehouse. I just can't figure out how to reproduce my Putty connection using a shell command.
Short recap:
I first connect to the proxy server which maps the port 5432 to my local port 10001. After that, i connect to the database server and map its 5432 port to my proxy's 5432 port, which I previously mapped to my 10001 port locally. I am then able to connect to the databse via a database manager locally.
To do so:
I created the following connection to my proxy server first.
I then added a tunnel from there to my localhost port 10001.
Once I'm logged in to the proxy server, I use the following command to connect to the database server and map its 5432 port to the proxy's 5432 port.
ssh username#databaseServer -L 127.0.0.1:5432:databaseServer:5432
I'd like to leave putty and move to WinSSHterm, predefine some login commands for a specific server.
How may I reproduce the behavior above using a shell command?
Here's my initial try, which is unfortunately not working:
ssh username#databaseServer -L 127.0.0.1:5432:databaseServer:5432
Thank you
I was finally able to find the correct way to write it.
Loginc Cmds
ssh username#databaseServer -L 127.0.0.1:5432:databaseServer:5432
Cmd-line Args
-L 10001:localhost:5432

Runing rsync to new website gives connection refused

We have an inhouse backup server (ubuntu) the inhouse server calls numerous remote servers using rsync. In order to set this up with a new website i need to ssh into the remote server and add my key to the authorized_keys file. Once i can login to the remote site via ssh from the backup server the rsync is then ran manually to build the structure (no reason for this but to confirm and to speed the backup up).
Today however I'm trying to add our newest website to the backup but the rsync command gives a 255 error and fails to connect due to a connection refused issue.
To confirm:
The remote server is lightsail with lampstack
We have multiple sites being backed up with lightsail and we use other servers too
Yes I can ssh into the remote site from on the backup server so key is correct and matches whats used in the rsync command
The rsync is generated and copied and pasted and has worked before
The .ssh folder on remote is 0700 and the authorised_keys is 600 and owner is bitnami
The pem file is in the correct folder /var/www/.ssh on backup server
The user I'm logged in as on the remote server when i run this is www-data (for ssh and rsync)
simplified rsyn command is:
rsync -rLDvvvcs -e "ssh -i /var/www/.ssh/LightsailKey.pem -p 22 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress --exclude-from '/path/to/exclude.txt' --delete --backup --backup-dir=/deleted_files/project-name/ --chmod=Du=rwx,Dgo=rx,Fu=rw,Fgo=r bitnami#{ip}:/home/bitnami/live/my-website/htdocs/ /mnt/incs/project-name/htdocs
Error from running this is
ssh: connect to host {ip} port 22: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(235) [Receiver=3.1.2]
[Receiver] _exit_cleanup(code=12, file=io.c, line=235): about to call exit(255)
What am i missing with this?
thanks
Turned out it was a typo in the ip field in the database.

Remote SQL Server

I am using Microsoft SQL Server on my mac through a docker container. I currently have a database on my local host. I want to share it with another computer/user so that they can get access to the DBMS and use C#. They are getting a error something like 'the server is not found or accessible'.
How can i make the database remote?
search for my.conf file in container.
whereis mysql
change bind address value:
bind-address 0.0.0.0
Then try to connect remotely:
mysql -h <host-name> -P <port> -u <user-name> -p

How can I use SSH tunneling to connect to a remote MySQL server?

I'm using SSH tunneling for the first time, so I'm trying to understand how to configure it.
I've got a remote Linux server that hosts a MySQL database that I'm trying to connect to. In order to access the MySQL database directly through a software that only recognizes local databases, I suppose SSH tunneling would be the right way to set up the access, correct?
Now, I'm trying to set up the tunneling on my 'home' computer which is running the software that's trying to access the MySQL database. My first question is whether this is reverse tunneling or normal tunneling? Secondly, is it local tunneling or remote tunneling?
Finally, from what I understand, my code is supposed to look something like
ssh -L 8080:mylinuxserver.mycompany.com:22 myuser#mylinuxserver.mycompany.com
Is this correct? Is my source port '22' since I'm using SSH and is my destination port 8080 (or is there something more appropriate)?
When I try to use the above code, I am able to login using my passphrase (since my key is already in the MyLinuxServer) but when I ping localhost:8080, it cannot find the host.
What am I doing wrong?
I've got a remote Linux server that hosts a MySQL database that I'm trying to connect to
The command should be:
ssh -L 8080:localhost:3306 myuser#mylinuxserver.mycompany.com
Where:
8080: is hte local port on your workstation
localhost: is corresponding to mylinuxserver.mycompany.com
3306: the MySQL port on above localhost.
then connect (from your workstation) to MySQL as:
mysql -h 127.0.0.1 --port=8080
Besides, ping localhost:8080 is wrong. Ping cannot work that way.
Try this:
ssh -f ssh_user#mylinuxserver.mycompany.com -L 3307:mysql1.example.com:3306 -N
Next, to access the mysql your trying to connect to:
mysql -h 127.0.0.1 -P 3307