Home Import GPG Key
Post
Cancel

Import GPG Key

Import GPG Key

After re-installing the system, I lost all my git setting since I did not back up the gitconfig file.

  • I have a 2 gpg keys, one for Github and one for my personal Gitea Server.

    1
    2
    3
    4
    5
    6
    
    ## To Find Keys available/active on system
    gpg --list-keys
    # Using the github key as the global option
    git config --global user.signingkey $MY_GITHUB_GPGKEY$
    # Project-wise setting 
    git config user.signingkey $MY_OWN_GPGKEY$
    

How to re-import

  • locate the key first, in my case privategpg.key is the private gpg key
1
gpg --import ./privategpg.key

It will prompt for key password

1
2
3
4
5
6
7
8
9
10
# Terminal Output
gpg: directory '/home/mijazz/.gnupg' created
gpg: keybox '/home/mijazz/.gnupg/pubring.kbx' created
gpg: /home/mijazz/.gnupg/trustdb.gpg: trustdb created
gpg: key AA***********D: public key "MijazzChan <mijazz@vip.qq.com>" imported
gpg: key AA***********D: secret key imported
gpg: Total number processed: 1
gpg:               imported: 1
gpg:       secret keys read: 1
gpg:   secret keys imported: 1

Trust Ultimately

1
2
3
4
5
gpg --edit-key $GPG_KEY_EMAIL$

gpg> trust

5 -> Trust Ultimately

Sign the commit

Once the key has been imported, simply git commit -S ... will make git sign the commit. You may be asked for private key password if your key was generated with it.

This post is licensed under CC BY 4.0 by the author.