DEV Community

nabbisen
nabbisen

Posted on • Originally published at scqr.net

GPG secret key: How to change the passphrase

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


Enter fullscreen mode Exit fullscreen mode

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]


Enter fullscreen mode Exit fullscreen mode

Get the key in sec.

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



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


Enter fullscreen mode Exit fullscreen mode

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>


Enter fullscreen mode Exit fullscreen mode

Type as below:



gpg> passwd


Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode




Conclusion

This is how to change the password on GPG.

Wish you privacy protected well 😉

Top comments (0)