An SSH Tunnel can be used to send encrypted data between two servers. Once setup, the remote host will appear to be running locally on a specific port.

Optional – Setup SSH Keys

  1. Go to your home directory
    • cd ~
  2. If you already have keys (~/.ssh/id_rsa & ~/.ssh/ you can skip step 3
  3. Generate SSH keys
    • ssh-keygen -t rsa
  4. Place the ~/.ssh/ onto the remote server in ~/.ssh/authorized_keys

Create the SSH Tunnel

*** In this example we will be creating a tunnel on the local machine‚Äôs port 8484 that connects to the remote server on port 22

  1. On the local machine create a tunnel and have the process run in the background
    • ssh -N -L 8424:$REMOTEIP:22 root@$REMOTE_IP&
      • The 8424 represents the port that will be opened locally
      • The 22 represents the port that will be opened on the remote server
  2. You should now be able to run SSH commands through this tunnel, i.e.
    • rsync -avz -e “ssh -p 8424” –progress root@localhost:/tmp/ /tmp/

Leave a Reply

Your email address will not be published. Required fields are marked *