简体   繁体   English

如何在远程服务器上使用 gpg 签名密钥?

[英]how to use gpg signing key on a remote server?

Is there a way of using gpg key in a remote server for signing by gpg program(command line tool) on linux?有没有办法在远程服务器中使用 gpg 密钥在 linux 上通过 gpg 程序(命令行工具)进行签名?

I am using gpg for signing binaries on localhost with test keys.我正在使用 gpg 在本地主机上使用测试密钥对二进制文件进行签名。 Now I want to use the same type of keys accessed by a server.现在我想使用由服务器访问的相同类型的密钥。 I am looking for a realization just by changing the gpg tool's arguments.我只是通过更改 gpg 工具的参数来寻找实现。

You can do this with OpenSSH>=6.7 and GnuPG>=2.1.1你可以用OpenSSH>=6.7GnuPG>=2.1.1做到这一点

OpenSSH 6.7 introduced unix socket forwarding which will used to forward the gpg-agent socket. OpenSSH 6.7 引入了 unix 套接字转发,用于转发 gpg-agent 套接字。 And GnuPG 2.1 got rid of the secring.gpg delegating private key management to gpg-agent .并且 GnuPG 2.1 摆脱了将私钥管理委托给gpg-agentsecring.gpg This avoids having to keep the private key on the remote machine.这避免了必须在远程机器上保留私钥。

First you'll want to set up an extra-socket on the local client.首先,您需要在本地客户端上设置一个额外的套接字。 Add this line to your gpg-agent.conf将此行添加到您的gpg-agent.conf

extra-socket /path/to/extra-socket

Restart your gpg-agent重启你的gpg-agent

pkill gpg-agent
gpg-connect-agent /bye

Open an ssh connection to the remote server and forward the servers gpg-agent socket back to the client (make sure gpg-agent isn`t already running on the remote)打开到远程服务器的 ssh 连接并将服务器 gpg-agent 套接字转发回客户端(确保gpg-agent尚未在远程服务器上运行)

ssh -R ${GNUPGHOME:-~/.gnupg}/S.gpg-agent:/path/to/extra-socket remote-server

Note: GNUPGHOME refers to the home folder of gnupg on the remote .注意: GNUPGHOME是指远程GNUPGHOME的 home 文件夹 If it is different from the local GNUPGHOME , you'll have to adapt this.如果它与本地GNUPGHOME不同,则必须对其进行调整。

You should now be able to sign/encrypt on the remote server, provided it has your public key in the keyring.您现在应该能够在远程服务器上签名/加密,前提是它在密钥环中有您的公钥。

Note: You may need to add a graphical pinentry (qt,gtk) to your clients gpg-agent.conf , I'm not sure the curses one will work.注意:您可能需要在您的客户端gpg-agent.conf添加图形 pinentry (qt,gtk),我不确定诅咒是否会起作用。

By default, OpenSSH will not remove the the forwarded socket on the server upon closing the connection.默认情况下,OpenSSH 在关闭连接时不会删除服务器上的转发套接字。 This will prevent OpenSSH to create the socket during the next connection.这将阻止 OpenSSH 在下一次连接期间创建套接字。 If you have access to the servers sshd_config you may add the following line如果您有权访问服务器sshd_config ,则可以添加以下行

StreamLocalBindUnlink yes

or remove it in you logout script ( .zlogout , .bash_logout , ...)或在您的注销脚本中删除它( .zlogout , .bash_logout ,...)

rm ${GNUPGHOME:-~/gnupg}/S.gpg-agent

Further information can be found on this GnuPG wiki page.可以在此 GnuPG wiki 页面上找到更多信息。 https://wiki.gnupg.org/AgentForwarding https://wiki.gnupg.org/AgentForwarding

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM