How do you write an odbc.ini file with configured ssh tunelling? - macos

I'm on m1 mac, with tableau 2021.4, and as a result I'm forced to used the iodbc.org SDK. The app doesn't work or register drivers meant for the m1 mac so I've used the intel x86_64 mysql odbc driver. I'm not asking tableau support for reasons.
The mysql db I need to connect to is on a server I can't connect to directly (behind a vpc) and an ssh tunneling works sometimes within tableau. This link is the closest one to my problem. tableau_support. Regardless, The connection keeps dropping and I'm guessing it's due to the odbc.ini file being configured incorrectly.
Ive been referring to this as it's the closest thing to help me figure this out: iodbc but I'm at my wits end.
My odbc.ini file:
[connection_name]
Driver = /usr/local/mysql-connector-odbc-8.0.20-macos10.15-x86-64bit/lib/libmyodbc8w.so
Username = db_username
Database = db_name
Port = 3306
Server = db_name.xyz.us-east-1.rds.amazonaws.com
Hostname = ec2-##-##-##-##.compute-1.amazonaws.com
How can I write a mysql odbc.ini file with the correct parameters to set up an ssh tunnel or to work with an ssh tunnel?
As an addition, the db itself is not on localhost, it has its own different endpoint and I need to use a pem file to gain access to the server the db is hosted on.
...

What about creating SSH-Tunnel, similar to this?
ssh myaccount#db_server -L 9002:localhost:3306
Then connect to port 9002 on m1-localhost this will be forwarded to db_server.
If port 3306 isn't used on your m1, you can use it to simplify:
ssh myaccount#db_server -L 3306:localhost:3306 -N
Details: man ssh
Or simplified: http://lifesim.de/lex/ssh.html

Related

Access public PostgreSQL server (Amazon RDS) from personal computer through proxy

I'm new to Amazon Web Service (AWS).
I already created a PostgreSQL from AWS RDS:
Endpoint: database-1.XXX.rds.amazonaws.com
Port: 5432
Public accessibility: Yes
Availablity zone: ap-northeast-1c
After that, I will push my application that using the database to AWS (maybe deploy to EKS).
However, I want to try testing the database server from my local computer first.
I haven't tried testing from my laptop PC at home yet, but I think it will connect OK because my laptop PC is not using the HTTP proxy to connect to the network.
The problem is that I want to try testing from my company PC, which needs setup the HTTP proxy to connect to the internet. The PC spec:
Windows 10
Installed PostgreSQL 10
Firstly, I tried using psql command-line:
psql -h database-1.XXXX.rds.amazonaws.com -U postgre
> Unknown host
set http_proxy=http://user:password#my_company_proxy:3128
set https_proxy=http://user:password#my_company_proxy:3128
psql -h database-1.XXXX.rds.amazonaws.com -U postgre
> Unknown host
set http_proxy=http://my_second_company_proxy:3128
set https_proxy=http://my_second_company_proxy:3128
psql -h database-1.XXXX.rds.amazonaws.com -U postgre
> Unknown host
Then, I tried using the pgAdmin tool.
As from the internet post, it said that we can use "SSH Tunnel" for inputing proxy:
However, the error message will be shown:
So, anyone can help suggest if we can connect to the public PostgreSQL server through HTTP proxy?
I think problem is Postgres uses plain TCP/IP protocol and you are trying to use HTTP proxy. Also you're trying to create SSH tunnel against your HTTP proxy server which won't work.
So I'd suggest following solutions:
Use TCP proxy instead of HTTP proxy
Create an EC2 or any instance that has SSH access from your company network and has access to public internet. So that you can create SSH tunnel through that instance to achieve your goal.
NOTE: Make sure you PostgreSQL is accessible from public internet (although this is usually bad idea, but it's out of scope this question) sometimes security group configs prevent it to connect from public internet.
Just add all ports(5432,3128...) in the Security Group from your RDS and specify your IP. Don't forget "/32"
Let me add that "unknown host" is usually an indication that you're not resolving the DNS hostname. Also, your HTTP proxy should not interfere with connections to databases since they aren't on port 80 or 443. A couple of things you can try (assuming you're on windows) sub in your actual url:
nslookup database-1.XXXX.rds.amazonaws.com
telnet database-1.XXXX.rds.amazonaws.com 5432
You should also check the security group that is attached to your RDS and make sure you've opened up the ip address that you're originating from on port TCP/5432.
Lastly check that your VPC has DNS and Hostnames enabled. https://docs.aws.amazon.com/vpc/latest/userguide/vpc-dns.html#vpc-dns-updating

DBeaver connection via SSH tunnel

Using DBeaver, I'm trying to connect to my AWS ec2 instance where I've installed a MariaDB database.
I've created a new connection as:
Connection: AWS / Maria DB
Server Host: localhost (because I'm using ssh to connect)
Database, Username and Password: the right ones
Port: 3306
SSH tunnel on the connection:
Use SSH Tunnel: checked
Host/IP, Port and User: as suggested by the AWS documentation
Auth: Public Key
Private key: file .pem (the one I'm also using to connect via ssh from command line)
The connection works great at the beginning.
After some minutes of inactivity if I open a table the connection stucks and I need to invalidate/reconnect to fetch the data. This process sometimes is done by DBeaver, after 15 seconds of not fetching anything, but sometimes even if I wait 2 minutes it keeps running but fetching nothing.
Is there something I'm missing in my configuration? Or some configuration on the server maybe.. I don't know..
Have you ever had this problem?
Here I had the same situation. Previous versions of DBeaver used to keep the connection longer (I don't remember precisely which version), in the order of hours.
I solved this issue by using a VPN or a SSH port forwarding from my machine. So, it is the same configuration as yours with localhost, but the tunnel is done outside DBeaver.
config using pem key in shh tunel

How can I connect to a remote mongodb server using the mongo shell?

Trying to connect to a remote MongoDB server I get: socket operation timed out.
and the firewall log also doesn't mention any attempted connection.
I have the Mongodb running on a remote Windows 2012 vm.
I used --bind_ip 0.0.0.0 and added the firewall rules from the docs.
ping´ing from either client/server works and so does the vnc.
And I'm able to connect from the server using either localhost or the ip
Im new to networking and thought I slowly understand, but apparently thats not the case!
Is there anything else I did not consider?
Try this in your terminal
mongo -u <USER> -p <PASSWORD> <HOST>:<PORT>/<DB> --authenticationDatabase <AUTH_DB>

Multiple Reverse shells using the same public port

I´ve got a Server behind a firewall and the firewall only allows traffic through port 22. This server has both public and private addresses.
I´ve got also about 1K clients that I need to reverse shell to this server, and be able to choose one of them by id when I want that ssh reversed tunnel.
My goal is to make the clients connect to ssh server via port 22, and each one of this connections should be forwarded to localhost on port with the same id.
When I connect to the server with my laptop also via ssh, I would then ssh to localhost on the correct id and get the client shell.
Can someone provide me the good path to achieve this behaviour using bash, ssh and linux tools?
Note - I don´t want to use client.py and server.py cause most of my clients are android based and it could easily become a nightmare to install python on all of them.
The problem - it was solved using remote port forwarding:
ssh -R 21:localhost:8888 user#server
In this command the 8888 represents the terminal id. In order for this to work, had to add this line to my ssh conf:
GatewayPorts yes

Postgres: Unable to connect to domain socket

Running psql gets me this:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
I installed Postgres 9.3.3 using Homebrew.
which psql gives /usr/local/bin/psql
This seems to be a common issue. I'm terribly sorry to ask again, but I've gone through at least a dozen Q&As here and can't resolve the issue. A few posts I've gone through include:
Why am I getting a could not connect to server error for postgres in Mac OS Lion?
Postgres cannot connect to server on Unix domain socket 5432
Can not connect to local PostgreSQL
Many thanks,
Justin
Have you modified postgresql.conf to accept incoming TCP/IP connections? You should uncomment the listen_addresses parameter and set it to an appropriate subnet mask. Then in pg_hba.conf you have to add a line to enable connections to databases over TCP/IP. Both configuration files are in your data directory (don't know where that is on OSX).

Resources