How to connect Zeppelin to a database that is through an ssh tunnel - postgresql

I have a local zeppelin instance running on my mac at localhost:8080 and I am trying to connect to a postgres database that is remote. I can access it via ssh and have set up a key pair for my computer but I can't figure out how to have zeppelin query the db directly

I don't think Zeppelin currently support database connection via ssh.
But you can still use a ssh tunnel and connect to your database.
1/ Start a tunnel by running this in a console :
ssh -i PATH_TO_KEY -L 5432:localhost:5432 USER#HOST -N
Where USER is the username associated the key pair and HOST is the ip address of your postgres host
2/ Create the zeppelin interpreter as if postgres was running locally
(this means default.url = jdbc:postgresql://localhost:5432/ )

Related

Is there any possibility to establish a SSH tunneling from the server using the postgresql to the client

I have one server machine where PostgreSQL and SSH server is installed. I have another client machine from where i want to connect to the PostgreSQL on the server machine in a secure way. I used SSH tunnel which is working.
I tried to connect the client with server using:
$ ssh -L 3307:localhost:3306 user#Host -N -f
It is working. But now I am thinking whether it is possible to start the ssh tunneling from the server side. It means run a ssh command on server machine so that I get a more secure connection

how to connect mongodb via COMPASS is bastion host(jump) setup

So I am using a bastion host(jump server) to connect to mongo db. I can use it via command line but I want to connect via compass.
So I am having an ec2-A(public) which uses ec2-B(private) to mongo db. I now how to do it on windows via putty but how to do it on mac??
Using this to connect jump server
ssh -i ~/B.pem -o "ProxyCommand ssh -W %h:%p -i ~/A.pem ubuntu#ec2-xx-xx-xx-xxx.eu-west-2.compute.amazonaws.com" ubuntu#1xx.xx.48.xx
and then mongo connection command.

How do I do mongodump on a server and transfer that to my local machine using golang?

I wrote a go program ( which is basically the code in this example, Simple SSH port forward in Golang ) that connects to a remote mongodb server by creating an ssh tunnel. I can query the server using mgo api. Now, instead of querying the server everytime, I want to copy a few collections of the database to my local machine and query locally. It is important to note that I cannot copy it directly to my local machine as there is port forwarding involved. How can I achieve this ?
You are reinventing the wheel. Use cron to create an ssh tunnel to the destination and then use a local mongodump to connect against your local tunnel endpoint
ssh -f user#mongodb.example.com -L 27017:mongodb.example.com:27017 -N
mongodump localhost:27017 <your opts here>

pgAdmin4: Unable to connect to Amazon EC2 via SSH Tunnel

I have Amazon EC2 instance running Ubuntu. I have installed and configured PostgreSQL.
Contents of the file /etc/postgresql/9.3/main/pg_hba.conf:
local all all md5
host all all 0.0.0.0/0 md5
Also in postgresql.conf
I have set listen_addresses='*'.
The test command below is successfully starting psql console.
psql -U postgres testdb
Now I am trying to connect pgAdmin4 from MacOS.
I have created a SSH tunnel with following command:
ssh -i ~/.ssh/test.pem -fN -L 5433:localhost:5432 ubuntu#mytestdomain.com
Now I have following details in pgAdmin:
When I save, I get this output:
Unable to connect to server: server closed the connection unexpectedly. This probably means the server terminated abnormally before or while processing the request.
What am I doing wrong ?
Here is the solution,
install pgadmin 4 into your system. and configure the below-added configurations. if the below configurations do not work then please check that DB user permissions on AWS. because of the restriction on IP level so it may not be able to access.

Connecting to database through ssh tunnel

Our production databases are only accessible from the production application servers. I am able to login to production app servers and psql to the db, but I would like to setup a ssh tunnel to allow me to access the production db from my work box.
Ideally, it would be a single command that I could run from my workbox that would set up the tunnel/proxy on the production app server
Here is what I have come up with, but it doesnt work.
user#workbox $ ssh -fNT -L 55555:db.projectX.company.com:5432 app.projectX.company.com
user#workbox $ psql -h app.projectX.company.com -p 55555
psql: could not connect to server: No route to host
Is the server running on host "app.projectX.company.com" (10.1.1.55) and accepting
TCP/IP connections on port 55555?
The reported IP address is incorrect.
When connecting to the tunnel endpoint, the hostname is your local host, since that's where the forwarded port is exposed.
ssh -fNT -L 55555:db.projectX.company.com:5432 app.projectX.company.com
psql -h localhost -p 55555
BTW, PgAdmin-III provides ssh tunnel automation. On the other hand, it's a big GUI app without psql's handy \commands.
It's pretty trivial to write a sshpsql bash script that fires up the ssh tunnel, stores the pid of the ssh process, launches psql, lets you do what you want, and on exit kills the ssh tunnel. You'll also want to TRAP "kill $sshpid" EXIT so you kill the tunnel on unclean exits.