My scrapbook about anything which I learned or want to remember, Sometime about tech tips, thoughts and rambling. If you find anything useful don't forget to give thumbs-up :)

Breaking

Wednesday, October 2, 2024

Adding or Updating User/Email in GPG Key

Adding an user in GPG key is simple and pretty straight forward. Though, Updating information in GPG is to follow Add and Delete step. 


List GPG Key:

$ gpg --list-keys
/root/.gnupg/pubring.kbx
------------------------
pub rsa2048 2024-09-30 [SC] [expires: 2025-09-30]
3FFC7E834DABE525D0C21EF9159C52055D4F20BD
uid [ultimate] John Doe (This is a Dummy GPG Key for tutorials)
sub rsa2048 2024-09-30 [E] [expires: 2025-09-30] 

 

Edit Key:

$ gpg --edit-key 3FFC7E834DABE525D0C21EF9159C52055D4F20BD
gpg (GnuPG) 2.4.4; Copyright (C) 2024 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 rsa2048/159C52055D4F20BD
created: 2024-09-30 expires: 2025-09-30 usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/547187E858E6854D
created: 2024-09-30 expires: 2025-09-30 usage: E
[ultimate] (1). John Doe (This is a Dummy GPG Key for tutorials)
gpg>

 

Run adduid command

gpg> adduid
Real name: Another User
Email address: another@user.com
Comment: This is an another user for demo
You selected this USER-ID:
"Another User (This is an another user for demo) "
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
sec rsa2048/159C52055D4F20BD
created: 2024-09-30 expires: 2025-09-30 usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/547187E858E6854D
created: 2024-09-30 expires: 2025-09-30 usage: E
[ultimate] (1) John Doe (This is a Dummy GPG Key for tutorials)
[ unknown] (2). Another User (This is an another user for demo)
gpg>

 

Select the new user (uid 2)

gpg> uid 2
sec rsa2048/159C52055D4F20BD
created: 2024-09-30 expires: 2025-09-30 usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/547187E858E6854D
created: 2024-09-30 expires: 2025-09-30 usage: E
[ultimate] (1) John Doe (This is a Dummy GPG Key for tutorials)
[ unknown] (2)* Another User (This is an another user for demo)


 

Trust (trust) the new user (uid 2)

gpg> trust
sec rsa2048/159C52055D4F20BD
created: 2024-09-30 expires: 2025-09-30 usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/547187E858E6854D
created: 2024-09-30 expires: 2025-09-30 usage: E
[ultimate] (1) John Doe (This is a Dummy GPG Key for tutorials)
[ unknown] (2)* Another User (This is an another user for demo)
Please decide how far you trust this user to correctly verify other users' keys
(by looking at passports, checking fingerprints from different sources, etc.)
1 = I don't know or won't say
2 = I do NOT trust
3 = I trust marginally
4 = I trust fully
5 = I trust ultimately
m = back to the main menu
Your decision? 4
sec rsa2048/159C52055D4F20BD
created: 2024-09-30 expires: 2025-09-30 usage: SC
trust: full validity: ultimate
ssb rsa2048/547187E858E6854D
created: 2024-09-30 expires: 2025-09-30 usage: E
[ultimate] (1) John Doe (This is a Dummy GPG Key for tutorials)
[ unknown] (2)* Another User (This is an another user for demo)
Please note that the shown key validity is not necessarily correct
unless you restart the program.

 

Save (save) the changes

gpg> save
root@f4cedfb94453:~# gpg --list-keys
gpg: checking the trustdb
gpg: no ultimately trusted keys found
/root/.gnupg/pubring.kbx
------------------------
pub rsa2048 2024-09-30 [SC] [expires: 2025-09-30]
3FFC7E834DABE525D0C21EF9159C52055D4F20BD
uid [ unknown] Another User (This is an another user for demo)
uid [ unknown] John Doe (This is a Dummy GPG Key for tutorials)
sub rsa2048 2024-09-30 [E] [expires: 2025-09-30]

 

Force to run trustdb

You will not see the trust status right away, So, to force that we need to run the trustdb command

$ gpg --check-trustdb
gpg: marginals needed: 3 completes needed: 1 trust model: pgp
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
gpg: next trustdb check due at 2025-09-30
 
$ gpg --list-keys
/root/.gnupg/pubring.kbx
------------------------
pub rsa2048 2024-09-30 [SC] [expires: 2025-09-30]
3FFC7E834DABE525D0C21EF9159C52055D4F20BD
uid [ultimate] Another User (This is an another user for demo)
uid [ultimate] John Doe (This is a Dummy GPG Key for tutorials)
sub rsa2048 2024-09-30 [E] [expires: 2025-09-30]

Update User/Email:  

Updating the user or email address process include the step 1 which is adding the new user or email address and trust that information as mentioned above commands, then step 2 is to either delete the old user/email id or revoke that. 

 

Edit the key (--edit-key

$ gpg --edit-key 3FFC7E834DABE525D0C21EF9159C52055D4F20BD
gpg (GnuPG) 2.4.4; Copyright (C) 2024 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 rsa2048/159C52055D4F20BD
created: 2024-09-30 expires: 2025-09-30 usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/547187E858E6854D
created: 2024-09-30 expires: 2025-09-30 usage: E
[ultimate] (1). Another User (This is an another user for demo)
[ultimate] (2) John Doe (This is a Dummy GPG Key for tutorials)

 

Revoke the userid (revuid

gpg> uid 2
sec rsa2048/159C52055D4F20BD
created: 2024-09-30 expires: 2025-09-30 usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/547187E858E6854D
created: 2024-09-30 expires: 2025-09-30 usage: E
[ultimate] (1). Another User (This is an another user for demo)
[ultimate] (2)* John Doe (This is a Dummy GPG Key for tutorials)
# Running revoke user id for uid 2 
gpg> revuid
Really revoke this user ID? (y/N) y
Please select the reason for the revocation:
0 = No reason specified
4 = User ID is no longer valid
Q = Cancel
(Probably you want to select 4 here)
Your decision? 4
Enter an optional description; end it with an empty line:
> this user was a dummy user, hence removing it
>
Reason for revocation: User ID is no longer valid
this user was a dummy user, hence removing it
Is this okay? (y/N) y
sec rsa2048/159C52055D4F20BD
created: 2024-09-30 expires: 2025-09-30 usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/547187E858E6854D
created: 2024-09-30 expires: 2025-09-30 usage: E
[ultimate] (1). Another User (This is an another user for demo)
[ revoked] (2) John Doe (This is a Dummy GPG Key for tutorials)

 

Deleting the user id:

Deleting the user id or any information from GPG key is not advisable because we will lost the track why we have made that change. Deleting the information is simple as above commands - 

# Selecting the uid 2 (revoked one) 
gpg> uid 2
sec rsa2048/159C52055D4F20BD
created: 2024-09-30 expires: 2025-09-30 usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/547187E858E6854D
created: 2024-09-30 expires: 2025-09-30 usage: E
[ultimate] (1). Another User (This is an another user for demo)
[ revoked] (2)* John Doe (This is a Dummy GPG Key for tutorials)
gpg> deluid
Really remove this user ID? (y/N) y
sec rsa2048/159C52055D4F20BD
created: 2024-09-30 expires: 2025-09-30 usage: SC
trust: ultimate validity: ultimate
ssb rsa2048/547187E858E6854D
created: 2024-09-30 expires: 2025-09-30 usage: E
[ultimate] (1). Another User (This is an another user for demo)


So, as mentioned before, Updating the information in GPG key is 2 step process which includes add and then delete step. These steps are manual and need to executed by some human, though, we can automate these steps if need to run by some machine user which we will learn in next post.

Till then, Happy Learning !!
ASingh

 


No comments:

Post a Comment

Disclaimer

The postings on this site are my own and don't necessarily represent IBM's or other companies positions, strategies or opinions. All content provided on this blog is for informational purposes and knowledge sharing only.
The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of his information.