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.

4 Responses to Tramp with Multiple Hops

  1. David says:

    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.

  2. Phil says:

    It's worth noting that there's a gotcha if you're using this for getting sudo access on the remote host. See http://stackoverflow.com/a/16408592/324105 for details.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>