How to use sshpass when loging in to remote server with Emacs / Tramp

一曲冷凌霜 提交于 2019-12-25 05:51:09

问题


I found a related thread that describes how to login to a remote server using sshpass:

sshpass -p '<password>' <ssh/scp command>

How can logging in with password be accomplished in Emacs / Tramp?

I presently use the following and then enter the password manually:

C-x C-f /ssh:user@server:/home/user/public_html/

I have the following function, that I access from my right-click context pop-up menu:

(defun lawlist-remote-server-login ()
(interactive)
  (find-file "/ssh:user@server:/home/user/public_html/"))

回答1:


If you're simply trying to avoid typing your password, but you don't want to use SSH keys, you can use an authentication file.

From the TRAMP user manual:

4.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

The port can be any tramp method (see Inline methods, see External methods), to match only this method. When you omit the port, you match all tramp methods.

In case of problems, setting auth-source-debug to t gives useful debug messages.

Edit:

The specific code that worked for the OP without requiring GnuPG is reproduced below.

Emacs configuration:

(setq auth-sources '("/Users/HOME/.0.data/.0.emacs/.authinfo")) 

And in the .authinfo file identified above:

machine 12.34.56.789 login lawlist password 12345678 port ssh


来源:https://stackoverflow.com/questions/22972621/how-to-use-sshpass-when-loging-in-to-remote-server-with-emacs-tramp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!