使用Emacs / Tramp登录远程服务器时如何使用sshpass [英] How to use sshpass when loging in to remote server with Emacs / Tramp

查看:550
本文介绍了使用Emacs / Tramp登录远程服务器时如何使用sshpass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现一个相关的线程,描述如何使用 sshpass 登录到远程服务器:

  sshpass -p'< password>'< ssh / scp命令> 

如何使用密码登录 在Emacs / Tramp中完成? / p>

我目前使用以下方式,然后手动输入密码:

  Cx Cf / ssh:user @ server:/ home / user / public_html / 

我有以下功能,我从右键单击上下文弹出菜单访问:

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


解决方案

如果您只是想避免输入密码,但不想使用SSH键,您可以使用身份验证文件。



TRAMP用户手册


4.12.1使用验证包含文件



最初在No Gnus开发的包 auth-source.el 提供
从FTP文件读取密码的可能性是从
〜/ .netrc 。默认身份验证文件为〜/ .authinfo.gpg ,可以通过变量$ code更改
auth-sources 。



身份验证文件中的一个典型条目是

 机器忧郁症港口scp登录daniel密码geheim 

该端口可以是任何流行的方法(请参阅内联方法,请参阅 External
methods
),to只匹配这种方法。当您省略端口时,您可以匹配
所有流动的方法。



如果出现问题,请设置 auth-source-debug to t 给出有用的调试
消息。


编辑



在不需要GnuPG的情况下为OP运行的具体代码如下所示。



Emacs配置:

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

.authinfo 上面标识的文件:

 机器12.34.56.789登录法律清单密码12345678 port ssh 


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/"))

解决方案

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

这篇关于使用Emacs / Tramp登录远程服务器时如何使用sshpass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆