Gpg – can’t connect to `/home/${USER)/.gnupg/S.gpg-agent’: No such file or directory

Recently, I got below error while I was trying to create new gpg key:

can’t connect to `/home/aykut/.gnupg/S.gpg-agent’: No such file or directory
gpg-agent[27029]: command get_passphrase failed: Operation cancelled
gpg: cancelled by user
gpg: Key generation canceled.

One can think that the problem is gpg-agent is not working. Yes, that might be the case in your situation. So, you can first run below command and see what is going to happen:

gpg-agent --daemon

If the result says that some files are created and agent started to run now, I suggest you to try creating your gpg key again. Otherwise, if message says that the agent is already running, like in my case, probably issue is not agent related. In my case, I login to server as different user and then changed it with su command. When using pinentry, you must have the proper permissions of the terminal device (e.g. /dev/tty1) in use. However, with su (or sudo), the ownership stays with the original user, not the new one. This means that pinentry will fail, even as root. As a workaround, running the command with script worked:

script -q -c "gpg --gen-key" /dev/null

Also some suggested that changing device to second user also working, but I haven’t tried that:

chown ${TARGET_USER} /dev/ttyN  # where N is the current tty (login user)
su ${TARGET_USER} # (login user)
gpg --gen-key # (new user)
exit # (new user)
chown ${LOGIN_USER} /dev/ttyN  # change back to old user (login user)

Developers Rock!!!

Advertisements
This entry was posted in Linux, Shell Script and tagged , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s