Bonus Round

The code that I show above sets up connection sharing for ssh. If you want this to work reliably, you need to clear the socket files when your internet connection goes down. The following can accomplish this

First, create a script called ssh-cleanup and put it in your $PATH and put the following in it:

For a more permanent setup, do your configuration at the ssh level (which has the side benefit of working outside Emacs as well). In your ~/.ssh/config, define a host alias with additional options, and connect to the alias with Tramp. E.g. in ~/.ssh/config: