Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Emacs Tramp to double hop ssh?

Tags:

emacs

ssh

tramp

My campus only lets ssh access through a gateway server. So to access the cluster I am coding on I have to ssh to the gateway and then ssh to the machine I am working on. The connection is very slow at times and is frustrating to work on.

I would love to use something like tramp which I understand would have the buffer open on my local machine and only talk through the network when I save to disk. I am not very familiar with tramp at all and struggling to get it to work, especially through the double hop. The documentation says this is accomplished through defining proxies in tramp, but I am unable to understand the syntax.

Does anyone know how to use emacs to code through a double hop or have an alternate workaround for editing code through two ssh hops?

like image 286
f4hy Avatar asked Apr 03 '09 21:04

f4hy


3 Answers

At least as of Emacs 24 they have a new version of multi you can open paths like this:

   /ssh:bird@bastion|ssh:you@remotehost:/path

I can confirm that this works on my version of Emacs 24.3.1. The docs describe it here.

like image 186
Joseph Lisee Avatar answered Nov 05 '22 05:11

Joseph Lisee


If you have Emacs 24.3 or later, see Joe's answer for an alternative to the configuration described below. If you'll be using this double hop more than once, it may be worth either modifying tramp-default-proxies-alist as described below, or setting tramp-save-ad-hoc-proxies to t.


If you have Emacs 23.1 or later, then the multi method is no longer supported. You can achieve the same result by configuring "proxies".

In your .emacs config file add the following:

(add-to-list 'tramp-default-proxies-alist
                 '("HOSTB" nil "/ssh:USERA@HOSTA:"))

Where HOSTB is the destination host behind HOSTA.

Then type /ssh:USERB@HOSTB: and emacs will prompt for the HOSTA password then the HOSTB password.

like image 44
Tom Avatar answered Nov 05 '22 06:11

Tom


You should use ssh to do the double hop. In your .ssh/config:

Host <host that must be proxied too>
ProxyCommand ssh -qxT <gateway host> nc %h %p
like image 12
fuzzy-waffle Avatar answered Nov 05 '22 06:11

fuzzy-waffle