When adding a key using the cmd

Gpg2 –-homedir . –-gen-key

And Im getting the error

Can’t connect to the agent: Invalid value passed to IPC

This is something to do with the homedir parameter but I need it there as my keyring exists in that dir.


After finding several mailing list threads with no answer to this question, I finally got it working.

First: use absolute paths for the homedir. E.g. instead of --homedir=. use --homedir="$(pwd)"

If that alone doesn't fix it, manually launch gpg-agent passing the same homedir (kill any existing agents first)

gpg-agent --homedir="$(pwd)" --daemon
  • Manually starting gpg-agent like this answer describes illustrated the problem for me which was that the absolute path of the homedir was too long. The gpg-agent aborted with gpg-agent[3857]: socket name '/some/long/path is too long`. Changing to a shorter path fixed it and did not require manually restarting the agent. – starfry Jan 14 '17 at 23:23

Look in ~/.gnupg/gpg.conf and ~/.gnupg/gpg-agent.conf for a line with GPGHOME=

If you are looking to statically change the location of GPGHOME run as such: GPGHOME=$path_to_'.' // i.e. ~/gpgtweaks/ << being the . in your question

gpg2 --full-gen-key

In the event that you still fail to get an agent launch run:


that should force a agent restart also of use is ADDING use-agent in your ~/.gnupg/gpg.conf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.