After leaving Emacs open overnight, the SSH connection expires. However, the buffers that I left open, are still useful, and I want to continue working with them.

However, any action I do with Emacs (either using ivy-swiper or counsel-M-x, or ivy-switch-buffer) in the expired TRAMP buffer leads to an attempt of reconnecting to SSH, which is very annoying as it requires to enter password.

Is there a way to stop Emacs from trying to reconnect on every action that does not require a fresh version of a file explicitly?

This is my TRAMP config:

(use-package tramp
  :straight nil
  (setq tramp-terminal-type "tramp")
  (setq server-port "1492")
  (setq server-use-tcp t)
  (setq auth-source-save-behavior nil)
  (add-to-list 'tramp-connection-properties
           (list nil "remote-shell" "/bin/zsh"))
  (setq tramp-completion-reread-directory-timeout nil)
  (setq tramp-default-method "sshx")
  (setq tramp-use-ssh-controlmaster-options nil)
  (setq vc-ignore-dir-regexp
      (format "\\(%s\\)\\|\\(%s\\)"
  (setq tramp-verbose 5)
  (setq remote-file-name-inhibit-cache nil)
  (setq tramp-auto-save-directory "~/.emacs.d/tramp-autosave")

1 Answer 1


Since Emacs 27, there are the commands tramp-rename-files and tramp-rename-these-files. They are intended exactly for this case.

Read the Tramp manual, section Renaming remote files about.

  • Thanks, I appreciate the answer, but I'm not sure how this is helpful. At least it does not seem to be solving the problem that I'm facing.
    – xelibrion
    Aug 10, 2022 at 16:15
  • 1
    It gives you the possibility to locate the buffer to another location, preferred on your local machine. Then Tramp is out of the game, and it doesn't try to reconnect the stale host. This might be a temporary relocation, and once the connection is reestablished , you can move the files back. Aug 10, 2022 at 16:55
  • Ah I see, let me try this out, thanks!
    – xelibrion
    Aug 11, 2022 at 9:06
  • Unfortunately this does not seem to work for my case, as when I call tramp-rename-these-files AFTER the connection has been dropped, TRAMP attempts to re-establish the connection - exactly the thing I'd like to avoid.
    – xelibrion
    Aug 12, 2022 at 9:20
  • 1
    It should work. If not, pls write a bug report. Aug 12, 2022 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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