Question: I'm trying to use an SSH tunnel from home trough a computer in the university so I can access some articles. 

Both machines are running Ubuntu 11.04. The university's machine runs `openssh-server`. 

At home I followed these instructions:

1. open an ssh session:

```
ssh -D 9999 -C user@my_addr.com 

```
2. Then I configured Firefox to user SOCKS5 connection on port `9999` of `localhost`.

This works for some time. Then, it suddenly hangs the connection and the terminal just freezes.

What am I missing here?

Answer: 
Try `autossh`. It detects hung connections and reconnects automatically. I used it in a similar situation in the past and it worked well for me.

**EDIT**

1. I used to run it in `screen`, which has two benefits: run (sort of) in the background, and possible to return to the session later to check its status and debug if necessary, like this: 

```
screen -d -m -S my-autossh-tunnel autossh your_autossh_args

```

This will start screen in the background. If you want to check on the `autossh` process, you can reconnect to this `screen` session with `screen -R my-autossh-tunnel`
2. I used empty passphrase for convenience, but for added security I used the following options in the authorized\_keys at the remote end: 

> 
> 
> ```
> command="/bin/false",no-agent-forwarding,no-X11-forwarding,no-pty`
> 
> ```
> 
> 

This way the tunnel can be established with the key, and the shell cannot be misused for anything else.
I had the same problem with using VNC over SSH tunnel. The freezes occured frequently, both with putty (windows) and openssh (linux).

With putty I copied the connection profile and changed a few options just to see what happened and no more freezes! 
The changes in putty are:

Connection: 
UNCHECK "disable Nagle's algorithm"
 (I left "enable TCP keepalives" checked and "seconds between keepalives" at 30)
SELECT "internet protocol version" IPv4 (instead of "auto")

Connection - SSH:
CHECK "Enable compression"

I am not sure what option did the trick, but I am a happy camper now. I cant get it to freeze, but when I switched back to the old profile to check, it froze within a few seconds.

The freezes occured mostly when sending large updates over VNC, like scrolling a window.
Perhaps the disabled Nagle algorithm flooded the server with too many small packets or perhaps because ipv6 was disabled on the remote VNC server but not on the other hosts. It would require some more testing with the individual options to figure that out.