I have a target-server that is accessible by middle-server, and I want a terminal from my localhost to target-server, through middle-server.
No need to open a port in my localhost.
I have a target-server that is accessible by middle-server, and I want a terminal from my localhost to target-server, through middle-server.
No need to open a port in my localhost.
You can specify a command to execute in a remote host just after establishing the ssh connection. Therefore, you can open a connection to your middle host, and then chain an additional ssh connection to your target server. Keep in mind that the chained command will execute at the remote host. This is particularly important if some of the IP addresses are set by local networks, behind NATs, etc. You could build a longer chain if you needed more hops.
ssh -A -t -p middle-port middle-user@middle-server ssh -A -p target-port target-user@target-server
If you need to use a certificate in some of the hops (lets say, to reach the middle server), then you should insert the -i argument in the first level of the chain. You might be prompted for a passphrase, if that is the case:
ssh -i ~/mykey.pem -A -t -p middle-port middle-user@middle-server ssh -A -p target-port target-user@target-server