你只需要启用ssh的 connection sharing功能就行了. 方法是编辑本地的 ~/.ssh/config
文件然后添加下面这些配置:
Host *
# Enable connection sharing.
ControlMaster auto
ControlPath ~/.ssh/%r@%h:%p
# Make persistent connections that can be reused.
ControlPersist yes
# Keep connections alive (helps TRAMP to detect disconnects.)
ServerAliveInterval 5
然后在Emacs中配置参数 tramp-use-ssh-controlmaster-options
为 nil