GPG secret key: How to change the passphrase

created
( modified )
@nabbisen

Series


Summary

Suppose you get along with GPG (The GNU Privacy Guard, GnuPG) for good privacy, and sometimes want to change the passphrase of its secret key.

This post shows how to do it.

To be short:

  1. Get the secret key ID
  2. Run gpg --edit-key ${the-key} to start the prompt
  3. Run passwd

Environment

Description

First, get the secret key ID by running:

$ gpg --list-secret-keys --keyid-format=long

It will print out like below:

/home/${USER}/.gnupg/pubring.kbx
---------------------------------
sec   rsa4096/${KEY:LIKE-123ABC456DEF} 202X-XX-XX [SC]
      ${HASH}
uid                 [...] ${NAME} <${EMAIL}>
ssb   rsa4096/${SUBKEY} 202X-XX-XX [E]

Get the key in sec.

Next, run gpg with --edit-key option and the key:

$ gpg --edit-key ${KEY:LIKE-123ABC456DEF}

Then it will show information on the key like below and start the prompt:

gpg (GnuPG) 2.2.40; Copyright (C) 2022 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Secret key is available.

sec  rsa4096/${KEY:LIKE-123ABC456DEF}
     created: 202X-XX-XX  expires: never       usage: SC  
     trust: unknown       validity: unknown
ssb  rsa4096/${SUBKEY}
     created: 202X-XX-XX  expires: never       usage: E   
[...] (1). ${NAME} <${EMAIL}>

gpg>

Type as below:

gpg> passwd

The current passphrase will be required:

gpg-change-passphrase-01

Finally, fill the new passphrases:

gpg-change-passphrase-02

Done without any output if there is no error. You can exit with:

gpg> quit

Conclusion

This is how to change the password on GPG.

Wish you privacy protected well 😉

Series

gpg
  1. GPG secret key: How to change the passphrase

Comments or feedbacks are welcomed and appreciated.