Search code examples
emacssshtramp

Emacs Tramp ssh double hop


Could somebody please help me setup Emacs Tramp to do a double hop? I want to work on machine2.abc.def.edu to which I can connect only through machine1.abc.def.edu. My username is myname, on both machines same.

I've tried to add .emacs:

(add-to-list 'tramp-default-proxies-alist
          '("\\`machine2\\.abc\\.def\\.edu\\'"
            "\\`myname\\'"
            "/ssh:machine1\\.abc\\.def\\.edu:"))

This is my best guess interpretation of what's in the manual. Then I do: C-x C-f /ssh:machine2.abc.def.edu or: C-x C-f /ssh:rsuhada@machine2.abc.def.edu

But both give:

ssh: Could not resolve hostname ssh: nodename nor servname provided, or not known
Process *tramp/scpc ssh* exited abnormally with code 255

And my Aquamacs can't be quitted and have to killed from shell... There is a 2 years thread here with same question. I've tried the answer from there:

(add-to-list 'tramp-default-proxies-alist
          '("machine2.abc.def.edu"
            nil
            "/ssh:myname@machine1.abc.def.edu:"))

With same results... also for all combinations I could come up with... Remote editing on machine1.abc.def.edu works fine, though.


Solution

  • Okay, let's try something different then, without opening a tunnel. How about the following in your .emacs file:

    (add-to-list 'tramp-default-proxies-alist 
                 '("\\`machine2\\'" 
                   nil 
                   "/ssh:%u@machine1.abc.def.edu:"))
    

    This is different from the code you found in the forum post in two points:

    1. it adds ticks around the target host name (Emacs regexp syntax to avoid matching partial names)
    2. it uses only the subdomain name in the target host (you reported in a comment below that you cannot ssh to machine2 when you use the full domain name)

    Does that help when you try to access a file on machine2?