Mount a remote server with a proxy - ssh

I'm trying to mount a remote directory From a server B on my local machine.
The connection to server B is possible only from a server A ( I can connect to using ssh ).
It's like making the server A as a proxy for the server B.
So i'm asking if there is a way to do this ?
Thanks.

You can use a Proxy Jump.
For that you can add server B in your local machine's ssh config file:
Host ServerB
HostName serverb.adress
User usernameInServerB
ProxyJump server.a.adress
Then you can just use any usual ssh command on ServerB, for example:
ssh ServerB
or
sshfs ServerB:Path/To/Dir

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

Connect from local PC to remote server with Docker web server

my Docker-Container is on my server.
Via SSH I can connect to the server from my local PC.
ssh user#RemoteServerIP -p 3360
From there I can connect to the Docker container via SSH
ssh userRemoteServer#DockerContainerOnServerIP -p 22
A Apache Webserver is running on the Docker-Container.
How can I access the Webserver on my local computer?
from you server try to figure out which port the apache container is using.. you can use netstat command sudo netstat -ntlp usually in the PID/Program name docker port is PID/docker-proxy .
after you know which port apache container is using, then u can access it using yourServerIP:ApacheContainerPort from you local computer
assuming of course the way you exposing apache port inside container is correct.

Forward website traffic to a different firewalled server using SSH

I'm trying to forward website traffic to a secondary server (as a temp workaround) using SSH.
ServerA for example can be accessed with serverA.example.com:8080
ServerB can't be accessed from outside, but running a wget localhost:8888 on ServerB returns the website I want to display on serverA.example.com:8080
Both serverA and serverB can be SSH'ed into.
I'm guessing for this scenario, Remote Forwarding is needed ...
So from ServerA, I run the following:
ssh -R8080:localhost:8888 jan#serverB.example.com
or
ssh -R8888:localhost:8080 jan#serverB.example.com
In both cases if I go to serverA.example.com:8080, I get a "This webpage is not available"
In short, I need to be able to point my browser to serverA:8080 which should forward it to serverB:8888 via SSH as SSH is the only open port on serverB.
Any idea how I can get this setup working?
You don't need to use Remote port forwarding -R but Local port forwarding -L. As this on serverA :
ssh -L8080:localhost:8888 jan#serverB.example.com
This will redirect local port 8080 from serverA to port 8888 on serverB through the ssh connection to serverB.
Be sure that nothing is running on local port 8080 on serverA before launching your command.

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