You can do this with OpenSSH>=6.7andGnuPG>=2.1.
OpenSSH 6.7 introduced unix socket forwarding, which will be used to forward the gpg-agent socket. And GnuPG 2.1 got rid of secring.gpgdelegating private key management before gpg-agent. This avoids the need to store the private key on a remote machine.
First you need to configure an additional socket on the local client. Add this line to yourgpg-agent.conf
extra-socket /path/to/extra-socket
Reboot gpg-agent
pkill gpg-agent
gpg-connect-agent /bye
Open an ssh connection with the remote server and send the gpg-agent server server back to the client (make sure that it gpg-agentis not already running on the remote computer)
ssh -R ${GNUPGHOME:-~/.gnupg}/S.gpg-agent:/path/to/extra-socket remote-server
Note. GNUPGHOMErefers to the gnupg home folder on the remote . If it is different from the local one GNUPGHOME, you will have to adapt it.
/ , keyring.
. , pinentry (qt, gtk) gpg-agent.conf, , .
OpenSSH . OpenSSH . sshd_config,
StreamLocalBindUnlink yes
script (.zlogout, .bash_logout,...)
rm ${GNUPGHOME:-~/gnupg}/S.gpg-agent