GPG high CPU usage

Today I had a very high CPU usage while using GPG.

I found the answer inside the following ticket https://dev.gnupg.org/T3972

The high CPU usage was caused by a process like this

/usr/bin/gpg –charset utf-8 –display-charset utf-8 –no-auto-check-trustdb –batch –no-tty –status-fd 2 –with-fingerprint –fixed-list-mode –with-colons –list-secret-keys *****

The reason is a huge key in ~/.gnupg/pubring.gpg. Mine was 37MB!!!

Thanks to “dkg” who publish the following awk script:

< ${GNUPGHOME:-~/.gnupg}/pubring.gpg gpg –list-packets | awk -F= -v oldoff=-1 -v keyid=unset ‘
/^# off=/{ off = $2 + 0 }
/^:public key/{
if (oldoff>-1) { print (off – oldoff) ” ” keyid };
oldoff = off; keyid = “unset”;
/keyid:/ {if (keyid == “unset”) { keyid = $1; } }
END { print (off – oldoff) ” ” keyid ; };’ | sort -n

There I get

36117 keyid: 6986401191B2164B
37146 keyid: 6BC26A17B9B7018A
51387 keyid: 702353E0F7E48EDB
53777 keyid: 3804BB82D39DC0E3
84346 keyid: 38DBBDC86092693E
94924 keyid: 79BE3E4300411886
902529 keyid: 2F3898CEDEE958CF
16676203 keyid: DB1187B9DD5F693B
20237699 keyid: 4E2C6E8793298290

The last lines are the problematic ones, there you can see that the keys are very huge. It’s time to wipe them out of the keyring

gpg –delete-key DB1187B9DD5F693B​

After deleting the two broken keys the filesize are reduced to 590K and GPG works like a charm.

Scroll to Top