Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enter gnupg-agent key passhprase from CLI?

Tags:

gnupg

I do sign commits with git, and it's a big problem that I can't enter gpg key passphprase from anywhere except CLI. If I'll do commit in vscode for example, it will fail. So I've came up with idea to just simply input passphrase from CLI, and cache it for some period of time.

I'm using fish shell in here so here's a config:

set -x GPG_TTY (tty)
eval (gpg-agent --daemon --allow-preset-passphrase  --default-cache-ttl 43200)

As I understand I need to enable to preset the passhprase for the agent. So now what's next?

I've tried to preset a key like this, but it fails:

$ echo mypassphrase | /usr/lib/gnupg2/gpg-preset-passphrase -c E2AB66331DA5CA780B7B1FA5D4BF11DA1E39EDFF

gpg-preset-passphrase: caching passphrase failed: Not supported

I've googled everything I could, but no one is answering this question anywhere. Would be nice to have something like ssh-add, you just add a private key, and enter password, wonder why gpg-agent haven't adopted this nice design.

like image 532
holms Avatar asked Mar 26 '18 12:03

holms


People also ask

How can I get passphrase from private key gpg?

Open the terminal application. Get a list of GPG keys by running the gpg --list-keys command. Run gpg --edit-key your-key-id command. At the gpg> prompt enter the passwd to change the passphrase.

What is GnuPG passphrase?

The gpg-preset-passphrase is a utility to seed the internal cache of a running gpg-agent with passphrases. It is mainly useful for unattended machines, where the usual pinentry tool may not be used and the passphrases for the to be used keys are given at machine startup. This program works with GnuPG 2 and later.

Why does gpg not ask for passphrase?

gpg caches the passphrase used for symmetric encryption so that a decrypt operation may not require that the user needs to enter the passphrase.


1 Answers

Seems to be solved. There's a need to add couple of things to ~/.gnupg/gpg-agent.conf:

default-cache-ttl 46000
pinentry-program /usr/bin/pinentry-gtk-2
allow-preset-passphrase

Reload gpg-agent

gpg-connect-agent reloadagent /bye
like image 114
holms Avatar answered Sep 22 '22 14:09

holms