yaobin.wen

Yaobin's Blog

View on GitHub
20 February 2022

Forwarding `gpg-agent` to a Remote System over SSH

by yaobin.wen

This article is a summary of Forwarding gpg-agent to a remote system over SSH. I re-organized the information to make it easier to follow. I’m not contributing new content so credits mostly go to that Wiki article.

Overview

Two hosts are involved:

Two pieces of software are involved:

Remote Host

On the remote host:

Local Host

On the local host:

Host <remote-host-short-name>
    HostName <remote-host-IP>
    RemoteForward <remote-agent-socket> <local-agent-extra-socket>

Use Scenario

When the configuration above on the local and the remote hosts are finished, run ssh -l <ssh-login-user> <remote-host-short-name> to log into the remote host, then run gpg. If passphrase is needed, the passphrase prompt will be prompted on the local host.

FYI: The passphrase prompt program is one of pinentry-*, such as pinentry-curses and pinentry-gnome3. gpg(1) has the CLI option --pinentry-mode to control passphrase entry behavior.

Notes

On Systems where systemd controls the directories under /var/run/user/<uid> it may be that the socket forwarding fails because /var/run/user/<uid>/gnupg is deleted on logout. To workaround this you can put gpgconf --create-socketdir in the startup script of your shell e.g. ~/.bashrc or ~/.zshrc.

Remote gpg will try to start gpg-agent if it’s not running. Remote gpg-agent which will delete your forwarded socket and set up it’s own. To avoid this you can pass --no-autostart to remote gpg command.

Tags: Tech