Tramp with Multiple Hops

The Emacs Tramp package is a wonderful thing. With it, you can easily edit files on remote machines in a virtually transparent fashion. Most Emacs users are familiar with Tramp and use it to edit files on machines on the local network or on remote-network machines directly reachable on the Internet. Often times, though, those remote-network machines are not directly reachable.

A typical example occurs when a developer is working from home and needs to access a machine on his work network that is protected by a firewall. Emacs, of course, can also handle this case. The normal way is to set rules for how to reach remote-network hosts in your .emacs or init.el file. The rules are a bit complex but are documented in the Tramp manual. Sometimes, though, you just want a one-off access to some protected host and it's a pain to temporarily add Tramp configuration rules for it.

Fortunately, David Vázquez has tweeted the answer:

Unless you need to repeatedly access some remote host, this is a much easier method. The tweet tells you just about everything you need to know but you can see the details in the Tramp documentation.

This entry was posted in General and tagged . Bookmark the permalink.
  • David

    I don't think you should mess with the tramp configuration if you need regular access to some hosts via a hopping-host. Just set up a proper .ssh/config:

    Host hopping
    User yourusername
    HostName hoppinghostname

    Host some hostname patterns
    User yourusername
    ProxyCommand ssh -q hopping exec nc %h %p

    This has the big advantage that normal ssh commands like ssh and scp will also handle the connection via the hopping server in a transparent way.

    But the tramp multi-hop feature still seems to be useful if you don't want to change your .ssh/config for some one-off connections.

  • Phil

    It's worth noting that there's a gotcha if you're using this for getting sudo access on the remote host. See for details.

    • jcs

      Yup. I wrote about that here. Figuring out how to do that was a big step forward in improving my workflow.

      • jcs

        And now I notice that Michael Albinus commented about the ad hoc multi hop method in that old post of mine. I'd forgotten all about it.