From charlesreid1

SSH for Linux Tasks

many useful tasks that can be done over SSH. unfortunately, most windoze networks block port 22.

SSH tunnels

Mostly stuff we already know - but you can build ssh tunnels. This allows you to access services locally that originate from another computer or server.

This capability enables you to bypass local DNS filtering (by routing DNS queries through the SSH tunnel instead of to the network's default DNS).

It also allows you to access servers on a private network, from a remote location.

Create ssh tunnel

You need ssh on both the client and server side. You'll run an SSH server on the server side, and connect to it with an SSH client on the client side.

From the client, you'll connect to the server with the ssh command, but with some additional flags that create the SSH tunnel: ssh -L <local-port>:localhost:<remote-port> username@

Here is what the syntax means:

to forward port 8001 on my local machine, the client, to port 8000 on the remote machine, the server, at IP address, I will run the following ssh command:

ssh -L 8001:localhost:8000 username@

create ssh tunnel through gateway node

suppose we have a gateway node, that is, a device that is able to access two different networks, one private and one public. in practice, this would be a publicly available server on a private network.

Suppose we are sitting at a remote computer, and we want to access a computer inside of a private network at

We can access a gateway node, which has a public ip address of and is also connected to the private network at

From the remote computer, we can ssh into, and set up the SSH tunnel to forward a port from the the computer we want to access, at, through to the computer at, and on back to the remote computer.

If we want to forward port 8000 on the computer inside the private network at through the gateway node and on to port 8001 on our remote machine, we would execute the following ssh command:

$ ssh -L 8001: username@

This will connect to with username, and will then connect to

Now port localhost:8001 on the remote machine will forward to

SSH configuration

You can configure ssh by editing system-wide configuration files (affects everyone) or user-specific files (affect only you).

User-specific ssh configuration

User specific configuration file for ssh is located in ~/.ssh/config

Example of file defining several hosts with fixed IP addresses:

Host dummy
Port 22
User foobar

Host dada
Port 20
User stein

These entries can be modified to add a server alive interval, which specifies an interval at which to send a keep alive packet to keep your connection alive.

Example modification:

Host dummy
ServerAliveInterval 60
Port 22
User foobar

to set keep alive interval for all hosts:

Host *
ServerAliveInterval 60

System ssh configuration

To change ssh config for whole system, use files at

/etc/ssh/ssh_config - just config for clients
/etc/ssh/ssh_config - config for everything\


mosh = mobile shell

combination ssh/multiplexer

keeps your session alive even if connection drops

apt-get install mosh

works just like ssh:

$ mosh username@
$ mosh -p 2332 username@


"Mastering Linux"