The cache expiry

(setq password-cache-expiry nil)

works only for the livetime of the emacs client. But I found in the Tramp user manual the possibility to store passwords permanently

5.12.1 Using an authentication file

The package auth-source.el, originally developed in No Gnus, offers the possibility to read passwords from a file, like FTP does it from ~/.netrc. The default authentication file is ~/.authinfo.gpg, this can be changed via the variable auth-sources. A typical entry in the authentication file would be

machine melancholia port scp login daniel password geheim

How do I setup this permanent password storage?

  • 2
    If you are connecting via SSH, I'd rather use ~/.ssh/config file to store connection settings. Note that using passwords for SSH connection is generally not advisable since asymmetric cryptography provides much better protection. The only valid uses could be if you connect to a machine with no internet access or similar cases when security doesn't matter.
    – wvxvw
    Feb 2, 2015 at 8:59

2 Answers 2


Do as recommended in the Tramp manual. Write your settings into ~/.authinfo.gpg. This requires a more recent Emacs which supports auth-source.el, I guess any Emacs 24.* should do.


In addition to the Tramp manual, there's a full manual for auth-source.el: (info "auth") that I wrote, which may help you. In the case of SSH logins, you may find it better to avoid passwords altogether--look at SSH keys instead.

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.