For testing purposes, I need a PGP key for a specific uid that has already expired.

Using gpg --full-generate-key only gives me the following options:

Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years

So the nearest expiration date I can set is tomorrow, which means that I'd have to wait 24 hours before I can perform my tests.

Is there a way to create an expired key other than changing the system date and time?

(I'm looking for a solution on macOS or Linux.)


1 Answer 1


You can set an expiration timestamp (in UTC) by typing something like “20220623T223000” for June 23rd, 2022, 22:30:00 UTC.

GnuPG will still consider that expiration timestamps in the past are invalid. It will however accept to generate a key that will expire in a few second.

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.