The idea was simple: keep my passwords in the terminal with
pass, version the encrypted files with Git, and maintain
an encrypted backup on GitHub. The interesting part is that storing
.gpg files in a Git repository is not quite the same
as encrypting the entire repository.
I wanted both: individual passwords encrypted locally with GPG, and a remote Git repository encrypted again before anything is uploaded. The final setup uses pass + GnuPG + Git + git-remote-gcrypt + SSH.
This write-up covers the installation from scratch, synchronization, restoration on another machine, and the GPG/WSL problems I encountered along the way.
Password manager: pass
Local encryption: GnuPG
Version control: Git
Remote encryption: git-remote-gcrypt
Transport: OpenSSH
Remote: GitHub
1. How the whole thing works
There are two separate encryption layers.
+-------------------------+
| pass CLI |
| generate/show/insert |
+------------+------------+
|
v
+-------------------------+
| GnuPG |
| Encrypt each password |
+------------+------------+
|
v
+-------------------------+
| ~/.password-store |
| *.gpg + Git history |
+------------+------------+
|
v
+-------------------------+
| git-remote-gcrypt |
| Encrypt Git objects |
+------------+------------+
|
v
+-------------------------+
| SSH transport |
| GitHub |
+-------------------------+
pass encrypts individual password entries. Git tracks
changes. git-remote-gcrypt encrypts the repository
representation stored on GitHub.
SSH handles authentication and transport. It does not replace GPG encryption, and a normal Git push of encrypted password files does not automatically encrypt the rest of the Git history.
2. Installing the dependencies
On Ubuntu or Debian:
sudo apt update
sudo apt install -y \
pass \
gnupg \
git \
git-remote-gcrypt \
openssh-client \
pinentry-curses
Check the binaries:
pass version
gpg --version
git --version
command -v git-remote-gcrypt
command -v pinentry-curses
For Gentoo, the installation process is different, but the architecture is exactly the same: install the corresponding packages using Portage.
3. Creating or selecting a GPG key
If you already have a GPG key, do not generate another one just for this tutorial. List your existing keys:
gpg --list-secret-keys \
--keyid-format LONG \
--fingerprint
A key listing normally contains a primary key, its fingerprint, a user ID, and a subkey capable of encryption.
If you do not have a key, generate one:
gpg --full-generate-key
Choose a suitable supported algorithm, specify your identity and protect the private key with a strong passphrase.
The primary fingerprint identifies the key that will be used for the password store and the encrypted remote.
gpg --list-secret-keys \
--with-subkey-fingerprint
For the remaining commands, replace
SEU_FINGERPRINT_GPG with your real fingerprint.
4. Initializing pass
A new password store can be initialized with:
fingerprint_gpg="SEU_FINGERPRINT_GPG"
pass init "$fingerprint_gpg"
The default directory is:
~/.password-store/
The .gpg-id file records which GPG recipient is
authorized to encrypt passwords.
Now create a test entry:
pass generate laboratorio/conta-teste 20
Read it:
pass show laboratorio/conta-teste
Or copy it to the clipboard, if clipboard support is available:
pass -c laboratorio/conta-teste
The password store now contains a GPG-encrypted file. No plaintext password needs to be committed to Git.
5. Preparing Git
Configure the Git identity, if you have not done so:
git config --global user.name "Seu Nome"
git config --global user.email \
"seu-email@example.com"
Initialize Git integration inside the password store:
pass git init
cd ~/.password-store
git branch -M main
git status -sb
The pass git command operates on the repository
associated with the password store.
When Git integration is enabled, commands such as
pass generate, pass insert and
pass rm can record changes automatically.
If you already have a Git repository with an established history, do not blindly reinitialize it or overwrite its remote.
6. Configuring GitHub SSH authentication
Check whether you already have a working SSH key:
ls -la ~/.ssh
ssh -T git@github.com
If no suitable key exists, generate a dedicated Ed25519 key:
ssh-keygen -t ed25519 \
-f ~/.ssh/id_ed25519_pass_backup \
-C "pass-backup"
Add its public key to your GitHub account under Settings / SSH and GPG keys.
Only upload the public key:
cat ~/.ssh/id_ed25519_pass_backup.pub
Never upload the private key.
If you created the dedicated key, configure SSH to select it:
nano ~/.ssh/config
Add a GitHub host entry:
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_pass_backup
IdentitiesOnly yes
Preserve any existing SSH configuration and adjust the host entry if you already use multiple GitHub identities.
Then:
chmod 600 ~/.ssh/config
ssh -T git@github.com
On the first connection, verify the GitHub host-key fingerprint against the official GitHub documentation before accepting it.
7. Creating an empty GitHub repository
Create a new private repository named, for example:
password-store-backup
Do not initialize it with a README, license or .gitignore. An empty repository simplifies the first encrypted push.
A private repository is useful as an additional access-control layer, but privacy settings are not the encryption mechanism used in this setup.
8. Configuring git-remote-gcrypt
This is the part that distinguishes the setup from simply
pushing .gpg files to GitHub.
Inside the password store:
cd ~/.password-store
usuario_github="SEU_USUARIO_GITHUB"
repositorio_github="password-store-backup"
fingerprint_gpg="SEU_FINGERPRINT_GPG"
git remote add origin \
"gcrypt::git@github.com:${usuario_github}/${repositorio_github}.git"
git config remote.origin.gcrypt-participants \
"$fingerprint_gpg"
git config remote.origin.gcrypt-publish-participants \
false
git config gcrypt.require-explicit-force-push \
true
The gcrypt:: prefix tells Git to use the
git-remote-gcrypt transport helper.
The participants setting identifies which GPG keys are allowed to read and authenticate the encrypted repository.
Publishing participant identities is disabled here to avoid unnecessarily exposing recipient key identifiers.
The final setting requires an explicit force push. There is a reason for this, explained below.
9. First encrypted push
For a newly created, empty GitHub repository:
cd ~/.password-store
git status -sb
git log -3 --oneline
git push --force -u origin main
Important: this first push assumes the remote repository is empty and belongs exclusively to this password store. Do not reuse this command blindly against an existing repository.
During the upload, git-remote-gcrypt encrypts the repository objects and creates a signed, encrypted remote manifest.
A successful execution should include messages similar to:
gcrypt: Encrypting to: ...
gcrypt: Requesting manifest signature
To github.com:USER/password-store-backup.git
* [new branch] main -> main
At this point, GitHub stores the encrypted representation of the Git repository, rather than an ordinary readable Git history.
10. Synchronizing new passwords
Generate another test password:
pass generate -c laboratorio/segunda-conta 24
With Git integration enabled, pass records
the encrypted file in the local repository.
But a successful local commit does not prove that the GitHub backup has been updated.
Always distinguish these states:
GPG encryption -> Local password protected
Git commit -> Local history updated
gcrypt push -> Remote backup updated
gcrypt fetch -> Remote history verified
For subsequent synchronization, first fetch the remote:
cd ~/.password-store
git fetch origin main
git status -sb
git log --oneline origin/main..main
Check that the remote branch is an ancestor of the local branch:
git merge-base --is-ancestor origin/main main \
&& echo "Historico compativel" \
|| echo "Historico divergente"
If the history is compatible, the remote has not changed concurrently, and you are certain no other client is writing to the same repository, the explicit push is:
git push --force origin main
Finally, fetch again and verify:
git fetch origin main
git status -sb
When both branches are synchronized:
## main...origin/main
git-remote-gcrypt has a known limitation: its push implementation
effectively behaves like a forced update. Requiring
--force
makes that behavior explicit but does not make concurrent writes safe.
A fetch followed by an ancestry check still has a race window. For this
reason, avoid simultaneous pushes from multiple devices and reconcile
divergent histories before publishing.
11. The WSL / gpg-agent problem
One problem I ran into was intermittent failure to decrypt the remote manifest.
The error looked like this:
gcrypt: Decrypting manifest
gpg: public key decryption failed: No such file or directory
gpg: decryption failed: No such file or directory
gcrypt: Failed to decrypt manifest!
The interesting part was that the same GPG key could encrypt and decrypt local files. The secret keys were present, and the GPG agent was running.
So the first thing to check is not whether the key exists, but whether the key actually works:
gpg --list-secret-keys \
--with-keygrip
export GPG_TTY="$(tty)"
gpg-connect-agent updatestartuptty /bye
A simple round-trip test:
fingerprint_gpg="SEU_FINGERPRINT_GPG"
printf 'teste de criptografia\n' |
gpg --encrypt \
--trust-model always \
--recipient "$fingerprint_gpg" |
gpg --decrypt
If the plaintext comes back, local encryption and decryption are working.
In my WSL environment, the runtime directory reported by the shell differed from the directory containing the actual GPG agent socket:
XDG_RUNTIME_DIR=/mnt/wslg/runtime-dir
GPG agent socket:
/run/user/1000/gnupg/S.gpg-agent
Running the remote operation with the Linux user runtime made the manifest decrypt successfully:
cd ~/.password-store
XDG_RUNTIME_DIR="/run/user/$(id -u)" \
git ls-remote origin refs/heads/main
That was a successful diagnostic workaround in this environment, not a universal fix for every GPG error.
I would not globally overwrite XDG_RUNTIME_DIR
in ~/.bashrc just to accommodate gcrypt.
WSLg also uses its runtime directory for graphical integration.
If this specific workaround is necessary, apply it only to the Git commands involving gcrypt.
12. Configuring pinentry-curses
For terminal-based GPG authentication, configure
pinentry-curses:
mkdir -p ~/.gnupg
chmod 700 ~/.gnupg
nano ~/.gnupg/gpg-agent.conf
Add or update the pinentry setting, avoiding duplicate
pinentry-program directives:
pinentry-program /usr/bin/pinentry-curses
default-cache-ttl 28800
max-cache-ttl 86400
Restart the agent:
chmod 600 ~/.gnupg/gpg-agent.conf
gpgconf --kill gpg-agent
gpgconf --launch gpg-agent
export GPG_TTY="$(tty)"
gpg-connect-agent updatestartuptty /bye
These cache values determine how long the agent may retain authentication material. Shorter values reduce exposure on shared or unattended machines.
13. Do not blindly trust automatic hooks
I initially experimented with a Git post-commit hook to synchronize every password change automatically.
The problem is that a failed post-commit hook does not reverse the commit that already happened.
That means the terminal can display a successful password generation and local commit even though the remote sync failed.
[main abc1234] Add generated password
gcrypt: Failed to decrypt manifest!
Local commit: yes
Remote synchronization: no
For a password backup, silently assuming that the remote is synchronized is worse than requiring one extra command.
My preference is to keep the Git commit automatic but make the remote synchronization a separate, explicitly verified operation. If a hook is used, it must clearly report failures, retain pending commits and avoid unattended force pushes.
14. Restoring the password store on another machine
The most important requirement is not the GitHub account. It is access to the correct GPG private key.
On the new Linux machine, install the same tools:
sudo apt install -y \
pass \
gnupg \
git \
git-remote-gcrypt \
openssh-client
Restore your GPG private key from a secure backup and configure GitHub SSH authentication.
Then clone the encrypted repository:
usuario_github="SEU_USUARIO_GITHUB"
repositorio_github="password-store-backup"
git clone \
"gcrypt::git@github.com:${usuario_github}/${repositorio_github}.git" \
"$HOME/.password-store"
The clone operation requires access to the corresponding GPG private key to decrypt the remote.
The restored .gpg-id file should already identify
the intended GPG recipients. Do not unnecessarily reinitialize
the store, because changing recipients can trigger
reencryption of its entries.
Validate:
pass ls
git -C ~/.password-store status -sb
At this point the encrypted entries should be available, provided the correct private key was imported.
15. Backing up the private key
The GitHub repository is not a substitute for a GPG key backup. Losing the private key can make the encrypted repository permanently unreadable.
Store a protected backup outside GitHub and outside the password-store repository, preferably on encrypted offline media.
For example, export the key into a directory on removable encrypted storage:
fingerprint_gpg="SEU_FINGERPRINT_GPG"
diretorio_backup="/CAMINHO/DO/ARMAZENAMENTO-SEGURO"
umask 077
gpg --export-secret-keys \
--output "$diretorio_backup/chave-privada.gpg" \
"$fingerprint_gpg"
Only run this after replacing the backup path with an actual secure destination. Protect the exported file, keep an independent recovery copy and test restoration in a controlled environment.
Never commit exported secret keys to Git.
16. Security considerations
This setup protects the confidentiality of password entries and the repository contents stored remotely, but it does not solve every threat.
- Compromise of the unlocked local machine can expose passwords.
- A stolen GPG private key plus its passphrase can expose the backup.
- Clipboard contents may be accessible to other local processes.
- SSH authentication and GitHub permissions still matter.
- Forced pushes can overwrite concurrent updates.
- Remote deletion or account loss still requires independent backups.
- GPG agent caching is a convenience/security trade-off.
Encrypted synchronization is not the same thing as complete endpoint security, and an encrypted GitHub repository is not a complete disaster-recovery strategy.
17. Final verification
A few commands are enough to verify the most important components:
echo "=== GPG ==="
gpg --list-secret-keys
echo "=== SSH ==="
ssh -T git@github.com
echo "=== PASSWORD STORE ==="
pass ls
echo "=== GIT STATUS ==="
git -C ~/.password-store status -sb
echo "=== REMOTE ==="
git -C ~/.password-store \
ls-remote origin refs/heads/main
A valid remote branch and a clean synchronized Git status indicate that the encrypted remote is readable and the local branch is aligned with its remote-tracking reference.
If remote decryption fails, investigate that error before generating more commits or attempting a force push.
Conclusion
The final result is a terminal-based password manager with encrypted local entries, Git versioning, SSH authentication and an additional encryption layer for the remote repository.
What I like about this setup is that GitHub does not need to be trusted with the plaintext repository contents. The keys remain under my control, and the repository can be restored on another machine without depending on a proprietary password-manager backend.
What still matters is operational discipline: verify synchronization, maintain backups of the private keys, and avoid pretending that an automatic Git hook guarantees a successful remote upload.
The useful lesson wasn't just getting pass
to work with GitHub. It was separating the different
failure domains: GPG encryption, local Git history,
SSH transport and encrypted remote synchronization.
References:
passwordstore.org
GnuPG
Git Documentation
git-remote-gcrypt
GitHub SSH Authentication
Nenhum comentário:
Postar um comentário
Observação: somente um membro deste blog pode postar um comentário.