使用公共密钥身份验证使用Emacs编辑远程文件

pic*_*ico 39 emacs ssh tramp

当我只能通过SSH使用公钥认证访问远程主机时,如何使用本地Emacs编辑远程主机上的文件?Tramp处理正常的密码登录很好,但我无法弄清楚如何使用密钥对.我在两端使用unix/linux.

Lor*_*ren 40

没有TRAMP相当于ssh user@host -i private-key.pem.但是,如果运行shell命令ssh-add private-key.pem,则ssh(以及TRAMP)将自动private-key.pem用于身份验证.只需要ssh user@host在shell上工作,打开文件/user@host:~/filename.txt将在emacs中工作,而不会提示输入密码.

  • 如果您使用`〜/ .ssh/config`文件来管理密钥,请参阅[@Sebastien](http://stackoverflow.com/a/10738277/881224)的答案. (6认同)

Seb*_*tte 27

我没有得到您的问题,因为Tramp与公钥验证的SSH连接完美配合.例如,假设您已在以下位置设置以下配置~/.ssh/config:

Host remotehost
    User     mylogin
    Port     22
    Hostname remotehost.fqdn
Run Code Online (Sandbox Code Playgroud)

并假设您可以ssh remotehost在终端中正确运行,那么您可以使用TRAMP Cx Cf打开您的远程文件/remotehost:path/to/file

  • 这是一个很好的答案,只需要添加`IdentityFile~/.ssh/identity-file` (7认同)
  • 在 Emacs 26.01 中,我必须执行 Tram Cx Cf /ssh:mylogin@remotehost:/ 它工作得很好。 (3认同)