magit over tramp: re-use ssh connection
Asked Answered
F

1

8

magit seems to open a new ssh connection for every command. This becomes very annoying especially when staging more chunks, which takes noticeable time to establish the connection for each chunk.

(from shell, I have persistent ssh connections enabled via ./ssh/config)

I am not sure whether this is a magit or a tramp thing.

But my question is:

How can I make magit re-use the ssh-connection?

EDIT:

The client is

  • tramp 2.3.5.26.2
  • GNU Emacs 26.1.91
  • debian (testing)
  • this is the tramp configuration
    (add-to-list 'tramp-remote-path 'tramp-own-remote-path)
    (setq tramp-default-method "ssh")
    (setq tramp-inline-compress-start-size 1000000)
  • this is the relevant part of my .ssh/config
  ## generally re-use existing connections
  Host *
      ControlMaster auto
      ControlPath ~/.ssh/sockets/%r@%h-%p
      ControlPersist 600

  Host myhost1
       HostName 111.11.11.1
       User myuser
       ForwardX11 yes
       ForwardX11Timeout 596h
       IdentityFile ~/.ssh/id_rsa
       IdentitiesOnly yes
       ForwardAgent yes
       SendEnv LC_*
       ServerAliveInterval 300

The server is RHEL 7.6 (Maipo)

Feuchtwanger answered 13/5, 2019 at 4:22 Comment(5)
Which OS and which ssh client are you using? And which OS/server are you connecting to? And which Emacs version and tramp method are you using? These days Tramp will try to use ControlMaster by default with ssh methods in order to re-use an open connection; but that's not available on all systems (or at least there was a time when Windows+Cygwin couldn't do it).Gummite
Thanks for looking into this. I have edited the question to contain this informationFeuchtwanger
At a glance that all seems like it would be ok, provided RHEL supports it. In your .ssh/config file I'm not sure whether Host * is still applied when it matches Host myhost1, so you may want to verify that, but it shouldn't matter for Tramp in such a recent Emacs version, as it should be trying to use ControlMaster regardless. I would definitely try to confirm outside of Emacs whether ControlMaster is working for you, however. You ought to see a difference between ssh <host> and ssh -Snone <host> if it's working.Gummite
Play with tramp-verbose as well, and then check the *debug tramp/foo* to see whether you get any useful information in those logs.Gummite
Thanks for your further comments. It definitely works outside of emacs. I'll have a look at the tramp debug output and report back.Feuchtwanger
L
10

By default Tramp doesn't use the ControlMaster options defined in your SSH config file (see the Tramp FAQ):

Tramp overwrites ControlPath settings when initiating ssh sessions. Tramp does this to fend off a stall if a master session opened outside the Emacs session is no longer open.

The FAQ also shows how to configure the ControlMaster options for TRAMP:

(customize-set-variable
 'tramp-ssh-controlmaster-options
 (concat
   "-o ControlPath=/tmp/ssh-ControlPath-%%r@%%h:%%p "
   "-o ControlMaster=auto -o ControlPersist=yes"))

Alternatively, if you want to tell Tramp to use the customisations in your ~/.ssh/config file you need to change the tramp-use-ssh-controlmaster-options variable:

(customize-set-variable 'tramp-use-ssh-controlmaster-options nil)
Laclos answered 17/1, 2020 at 10:19 Comment(1)
Sorry for the long delay. Your solution from the FAQ solves my problem. Thanks!Feuchtwanger

© 2022 - 2024 — McMap. All rights reserved.