Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

magit over tramp: re-use ssh connection

Tags:

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)

like image 803
Andreas Avatar asked May 13 '19 04:05

Andreas


1 Answers

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)
like image 108
ph0t0nix Avatar answered Nov 11 '22 06:11

ph0t0nix