How Connect Unix Socket via SSH Tunnel in Datagrip - datagrip

How can I connect to a MySQL server via SSH Tunnel and get from the server the UNIX socket in Datagrip?
I found this partial solution, that helps me to configure SSH Tunnel but not get the socket file from the server.
How to connect to database through SSH using DataGrip
The server is MariaDB and I tried to use this information too but doesn't work
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360010247880-How-to-connect-to-mariadb-via-unix-socket-

unix socket is not forwarded via SSH tunnel unless you perform some additional steps. the best approach is to use socat. something like that before connection:
/usr/bin/socat "UNIX-LISTEN:$SOCKET_DIR/mariadb-remote1.sock,reuseaddr,fork" \
EXEC:'/usr/bin/ssh -F /etc/sshssh_config -l root <remote1 host> -p 22 /usr/bin/socat STDIO UNIX-CONNECT\:/run/mariadb/mariadb.sock'
Here and here you can find more useful information.

Related

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

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

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>

VNC viewer failing to make connection with "channel 3: open failed: connect failed: No route to host"

I ssh into a server with the following:
ssh -g -L5912:server:5912 user#host
It goes through, and I can access my files on the other server through the command line (meaning I can connect to the server, it is my vnc viewer that is failing!) but when I try to open my vnc viewer (RealVNC) and connect to localhost:12 i get the following error message in the vnc viewer application:
The connection closed unexpectedly.
Additionally in the original command line shell i get:
channel 3: open failed: connect failed: No route to host
I've tried switching to different ports and even checked out other posts on the same error message but the problem is i don't really understand them... ssh tunnels are still relatively new to me so i don't really know what im doing. Any help would be greatly appreciated. Thanks!
You're trying to setup a port forwarding, this may fail because of many reasons:
SSH port forwarding not enabled in the host
Check SSH server in the host if AllowTcpForwarding is enabled:
$ grep AllowTcpForwarding /etc/ssh/sshd_config
AllowTcpForwarding yes
Typically, it's commented out. Uncomment and restart the sshd.
No connection between the host and server over port 5912
SSH to the host and try:
$ telnet server 5912
Connected to server.
Escape character is '^]'.
Finally, does the server listen on 5912?
Similarly, as above, but from the server - go there and try telnet server 5912.
Best regards,
Jarek
In my case it was the port forwarding rule I had set in Putty.
Please make sure you enter the correct hostname when defining the rule in Putty. I changed
localhost:5903
with
myserver:5903
and it worked...

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

DBVisualizer Hive SSH Tunnel Ignoring Server Information

I'm attempting to setup a connection to our Hadoop cluster via DBVisualizer.
In order to connect I need to SSH into a server on the domain and then I need to run the command to a remote server (I've not ssh'd onto the Hadoop cluster directly)
I have (figuratively)
Database Server: abcd.efg
Database Port: 12345
Database: Hello
configured for the Database section
SSH Host: hijk.efg
SSH Port: 678
When I attempt a connection, it returns
Could not open client transport with JDBC Uri:
jdbc:hive2://127.0.0.1:-----
Where 127.0.0.1 and ----- appear to be the defaults instead of what I entered.
Any idea how I get the SSH tunnel to use the server configuration I specify?
The SSH Tunnel is set up locally on the client, so connecting to the port on localhost tunnels you to the SSH Host/Port, which then sets up a connection to the database server/port you have specified. This page may help:
http://confluence.dbvis.com/display/UG100/Using+an+SSH+Tunnel
Best Regards,
Hans

Resources