Mini Lexikon

SSH Tunnel

SSH Tunnels and port forwarding
  • we work on machine1 in net1
  • and want to connect to machine3/4 in net2
  • Local

    we want m3:80 and m4:81 via m2
    ssh myaccount@machine2 -L 9080:machine3:80 -L 9081:machine4:81 -g
    
    we get m3/4 on machine1:9080/9081 (localhost:908...)
    because of param -g we can connect from any machine in net1 via machine1:908...

    Remote

    we cannot connect to machine2, but friend in net2 machine2 can connect to us:
    he will initiate connection and establish a remote port forward
    ssh myaccount@machine1 -R 9002:machine3:80 -N
    
    we can connect from net1 machine1 via locahost:9002 to machine3:80
    we use -N so no other commands can be done on m1 from via machine2
    your ssh-port is not 22?
    i.e. use option -p 2222 for ssh-port 2222
    if connecting over internet you should check the fingerprint of the ssh-key:
    ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key
    
    or dsa or ecdsa_key
    Spenden / Donations in bitcoin 1KUUuU4mjtQLgPvTyaDZ5aJrz1waaSSwQa
    The intention was, to provide quick and easy to use information.
    For more info read the manpages or click man ssh