DEV Community

nabbisen
nabbisen

Posted on β€’ Originally published at scqr.net

5 1 1

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 πŸ˜‰

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

πŸ‘‹ Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay