Secure forwarding of services with SSH

Contents


Introduction and basic concepts

In addition to remote login and file transfer, you can use ssh to forward other services. Many services can be forwarded through the same ssh "tunnel". ssh has built-in support for intelligent X11 forwarding, and it can also do general forwarding from a port on the local machine to an arbitrary IP and port on the other end.

Another method altogether of doing this is to establish an encrypted IP link with the remote host and use normal network services over that link. This is often called a Virtual Private Network (VPN). One can set this up by using the PPP protocol over an SSH connection.


Automagic X11 forwarding

SSH will, by default, automatically set up X11 forwarding for you if you run the ssh client with your $DISPLAY environment variable set (i.e. if you are using X11). You can turn off this behaviour with command line switches as well as with the config file in your $HOME/.ssh directory. For most users, this is enough; it works quite transparently.

Underlying mechanism

SSH does several things to facilitate "more secure" X11 forwarding. I try to use the terms "ssh client", "ssh server", "X client", and "X server" in this section to help clarify things. Remember that the X server is the program that runs on your display and puts things into your framebuffer; the X clients are the programs (like xterm, fvwm, netscape) that connect to your display to tell it what to draw where. When you are using ssh and X11 you are usually running the ssh client on the same machine that the X server is running on (the machine you are sitting in front of), and the ssh server is running on the remote system, and you are running some X clients on the remote system and the ssh server is forwarding them to the ssh client which is forwarding them to the X server. Whew.


Secure port forwarding with "ssh -L"

You can forward arbitrary connections through your ssh tunnel using the -L option. This makes your ssh client listen on a given port and forward traffic received there through the tunnel; it instructs the remote sshd to send the traffic to a given IP address and port.

1011 (sergent@hill-b-118:~) ssh -L 4242:shay:23 shay
1001 (sergent@shay:~)
*switch window*
1007 (sergent@hill-b-118:~) telnet localhost 4242
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.


UNIX(r) System V Release 4.0 (shay.ecn.purdue.edu)

login:

ssh prints a message (in this case, "fwd connect from sergent@127.0.0.1 to local port sshdfwd-4242") to the tty running ssh so that you know the forwarded connection has been made.

You can use "ssh -R" to forward a port on the remote machine to the local ssh client.

Issues with port forwarding

This works fine for protocols like telnet and HTTP, but other protocols aren't so simple. For example, FTP makes a connection back to the client at an arbitrary port for the data connection. Your ftp client and daemon don't know to negotiate the connection through an ssh forwarded port. A good solution is to use HTTP instead to transfer the file. Other protocols may have similar problems, and similar solutions, too...


Virtual private networks

I hope to expand on this after the presentation.

VPN concepts (basics)

The idea behind a VPN is to create an encrypted tunnel between two sites on the Internet and route IP through the tunnel. To clients and servers on either end it looks like a normal network; the encryption and the fact that the rest of the Internet is between the two sides is invisible. We can use ssh to implement something like this.

VPN with SSH and PPPD

It's possible to run PPP (Point-to-Point Protocol) over an ssh connection. PPP can handle several different sorts of network protocols and the like. It represents the data as a stream of bytes, which ssh is great at handling.

Implementation with Linux pppd

Check out the ssh-ppp Perl script, which sets things up for you.

Jonathan Sergent <sergent@purdue.edu>