Managing ssh connection with an jumphost in between
My useful SSH/SCP commands to work with a Jumphost, but never want to touch it.
Open a Shell on the remot host
To connect a Unix machine which is only accessible via a jumphost directlty, you need to store your public key in the ~/.ssh/authorized_key
file on the jumphost. Afterwards you can access the remote host using following commands:
Port Forwarding
To access a Port on the remote Host we can use the buildin feature of TCPForwarding in OpenSSH. This allows us for example to open a HTTP website on our localhost which runs on the remote server.
At first we need to enable TCPForwarding in the Daemon configurationfile of SSH sshd_config
, per default TCPForwarding is enabled at least since OpenSSH Version 7.6p1.
As long as you keep the session open, you are now able to open up your favourite browser and type in following as URL: http://localhost:80
It should open the Website of the connecting remote host. Keep in mind you can do it with every Port(service) which runs on the remote host and listen to a network Port.
If you get an error like this:
Check if the service is really running on the remote host or if the port is listening netstat -tlnp
.
Filetransfer with Jumphost
We can use scp
to transfer files/ directories to our remotehost via the jumphost, similar to the first example to access the remotehost directly.