I was staring at a locked terminal, the passphrase prompt blinking like a heartbeat I couldn’t ignore.
GPG and tmux are two of the most powerful tools in a developer’s arsenal. GPG secures your secrets. Tmux keeps your sessions alive long after you close a laptop lid or lose a network connection. Together, they create a workflow that’s fast, stable, and secure. But combining them isn’t always obvious.
The challenge starts when GPG agent forwarding meets persistent tmux sessions. Without the right setup, your GPG keys vanish when the original shell dies. You’re left reentering passphrases or losing signed commits mid-workstream. The fix is simple if you know it, and essential if you value stability.
Setting Up GPG in Tmux
- Start by ensuring
gpg-agentis running outside tmux:
gpgconf --launch gpg-agent
- Export the
GPG_TTYvariable inside tmux:
export GPG_TTY=$(tty)
Add this to your shell config so it’s set on every tmux pane.
- Forward your
gpg-agentsocket into tmux sessions. For most setups, ensure:
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
- Reload your tmux environment after attaching:
tmux refresh-client -S
This ensures consistent behavior for GPG signing, encryption, and commit verification whether you’re connected locally, via SSH, or resuming a week-old tmux session.