Linux Tools, Utilities, and Other Services

This document provides basic tools and algorithms for use with data science and machine learning tasks in Python

Andrew L. Mackey

Overview

The following information is useful for various tasks to be performed in a Linux environment.

 

SSH Tunneling and Port Forwarding

It is generally preferred to have data encrypted when traveling across networks. One method for accomplishing this task is to tunnel traffic through an SSH connection between the client and some SSH server that has access to the destination server. The SSH server may also be the destination server.

Let’s consider an example. The client represents your personal computer, so it will have the IP address of 127.0.0.1 (localhost). The destination is some web server running on port 80 behind a firewall at address 10.0.0.50. Your computer cannot access this server directly. However, your computer can access IP address 20.20.20.20 running SSH on port 22, which has direct access to the destination web server (10.0.0.5). Our goal is to connect to the SSH server (20.20.20.20) and tunnel a connection between the client (127.0.0.1) and destination (10.0.0.50).

First, we start by picking some port we want to use on the client so that when we connect to that port locally, it will map that port to the destination. We will simply pick port 3000. This suggests we will map 127.0.0.1:3000 to 10.0.0.50:80. We specify the -L option to denote local port forwarding.

ssh  -L  [localaddr]:[localport]:[destaddr]:[destport]  [user]@[sshserveraddr] -p [sshport]

For our example, we will use the following command:

ssh  -L  127.0.0.1:3000:10.0.0.50:80  someuser@20.20.20.20 -p 22