I have 2 servers.
Server A
is behind a router, to which I have no admin access.- It has a user:
userA
- It has a user:
Server B (example.com)
is a cloud server with a public ip.- It has a user:
userB
- It has a user:
I am running the following command on Server A
, to forward any connections made to Server B
on Port 8022
back to Server A
on port 22
:
ssh -R *:8022:localhost:22 [email protected]
This creates a ssh connection and I have a session open for [email protected]
If I then open another terminal (on another computer) and ssh into [email protected]
and once connected run ssh userA@localhost -p 8022
I have an active ssh connection to Server A
This is new to me but all seems to make sense.
I would like to ensure that the inital remote forwarding connection ssh -R
is always active. This means if the connection drops I need it to reconnect. If Server A
reboots I need it to connect on startup.
How would I go about doing this?
Is there a better approach?