2

I'm using Magit over Tramp and my git push commands fail because tramp doesn't forward my ssh-agent to the remote machine.

In pseudo code, it looks like I need to do the following:

tramp-methods["ssh"][tramp-login-args].prepend( ("-A") )

How do I do this without copy/pasting the entire tramp-methods variable into my emacs init file? Or is there a better way to do this?

  • 1
    Check the Association-Lists section of the elisp manual. – npostavs Nov 20 '15 at 22:57
  • @npostavs: Thanks for the hint. Is there a better way to code "put something in list if not already there"? – Harvey Nov 21 '15 at 13:44
  • 4
    You could also use ~/.ssh/config to deal to this (from specific hosts) regardless of whether or not you're using Emacs to connect, by setting ForwardAgent yes for the host(s) in question. – phils Nov 21 '15 at 16:06
  • @phils: I probably should taken this approach form the start. I don't really like maintaining ssh_config files. – Harvey Nov 22 '15 at 17:19
3

Starting with Tramp 2.2.13, you will be able to overwrite entries of tramp-methods. In your case, you would do something like

(add-to-list 'tramp-connection-properties
             (list (regexp-quote "/ssh:user@randomhost.your.domain:")
                   "login-args"
                   '(("-A") ("-l" "%u") ("-p" "%p") ("%c")
                     ("-e" "none") ("%h"))))

Tramp 2.2.13 is integrated in the upcoming Emacs 25.1. Tramp 2.2.13 will be released itself at the end of this year. For the time being, you could use the development versions of Emacs or Tramp, of course.

  • Will you be able to modify the existing args or simply replace? One of the reasons I took the modify approach was so I wouldn't have to worry about stepping on future changes to tramp. – Harvey Nov 22 '15 at 17:34
  • 1
    It's not a modification or a replace, it is just a kind of overlay. tramp-methods keeps untouched. Settings in tramp-connection-properties are prioritized over tramp-methods. But you are right, likely there shall be a convenience function which returns the recent value of a given argument in tramp-methods; this would ease it to change. Will think about. – Michael Albinus Nov 22 '15 at 18:51
3

After suggestions...

(defun add-ssh-agent-to-tramp ()
  (cl-pushnew '("-A")
              (cadr (assoc 'tramp-login-args
                           (assoc "ssh" tramp-methods)))
              :test #'equal))
(add-ssh-agent-to-tramp)
  • This did it for me. can now multi hop into ec2 instance in private subnet. Thankyou! – Baggers Jan 8 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.