First of all, you need to install gpg into your operating system.
# for debian/ubuntu apt install gpg # for centos yum install gpg # for fedora dnf install gpg
Generate a new GPG key using the following command.
gpg --default-new-key-algo rsa4096 --gen-key
Provide your name and email address, and enter O to confirm your information.

It will then ask you to enter a password that protect your GPG key.

The following screen shows that your first GPG key is generated.

Then, use the following command to list your keys.
gpg --list-secret-keys --keyid-format LONG
What I framed in red is the GPG Key ID you’d like to use. In my case, it was 3EB8626831F6485A.

Use this following command to enable GPG signing and setting up your git signing key.
git config --global commit.gpgsign true git config --global user.signingkey 3EB8626831F6485A
Setting up the GPG_TTY environment variable in your shell dotfiles. Don’t forget to source it if you want to use it under current session.
test -r ~/.zshrc && echo ‘export GPG_TTY=$(tty)’ >> ~/.zshrc test -r ~/.bash_profile && echo ‘export GPG_TTY=$(tty)’ >> ~/.bash_profile echo ‘export GPG_TTY=$(tty)’ >> ~/.profileFinally, export the public key of your GPG key, copy it and configure it in your Github accounts.
gpg --armor --export 3EB8626831F6485A
Reference:
https://help.github.com/en/github/authenticating-to-github/generating-a-new-gpg-key