Generating New GPG and SSH Key for PR
Most of the documentation here is a shorten version for the Mac Operating system but most of the commands should be the same. For more information, please visit these following sites
- Generating a new GPG key — GitHub Enterprise Server 3.10 Docs
- Adding a GPG key to your GitHub account — GitHub Enterprise Server 3.10 Docs
If you already have existing/multiple GPG Keys, please visit the site below for the step-by-step process
GPG Key
First make sure that GPG command line is installed using the following packages
Next, open up terminal and run the following lines of command
# use this to generate a new key
gpg --full-generate-key
# use this instead if the previous command does not work
gpg --default-new-key-algo rsa4096 --gen-key
On the screen of the terminal, you will be given several prompts for you to answer but just press enter/return to accept the default setting. Afterwards, you will be told to User ID information (use the GitHub account you want your GPG keys to be associated with). Then you will be asked to give a secure passphrase (write this down) and run the following command
# use this to get the full list of keys
gpg --list-secret-keys --keyid-format=long
Next, we will get the GPG key from the example above, we will use C907E045540377E5. Next paste that key into the following command.
# replace <GPG Key ID> with your GPG Key ID
gpg --armor --export <GPG Key ID>
Finally copy the GPG key that starts with
----- BEGIN PGP PUBLIC KEY BLOCK -----
and ends with
----- END PGP PUBLIC KEY BLOCK -----
then add it to your GitHub account.
SSH Key
If you do not have SSH Key setup, you can use this section to set it up otherwise you can go to the section “Adding GPG and SSH Key to GitHub Profile” to add your keys to your account.
Open up terminal and run the following command
# replace the text <your GitHub email address> with your GitHub email
ssh-keygen -t ed25519 -C <your GitHub email address>
# use this command if your computer doesn't support Ed25519 algorithm
ssh-keygen -t rsa -b 4096 -C <your GitHub email address>
# output
# Generating public/private ed25519 key pair
Press enter/return to save the key a file space. Next, we will have to create a passphrase (remember this passphrase) because the next prompt will tell you to put in that same passphrase again.
Now, we want to add the SSH key to a ssh-agent using the command below
eval "$(ssh-agent -s)"
If the file doesn’t exist, then we can create the file using the command.
touch ~/.ssh/config
Next open up the file using this command
open ~/.ssh/config
Edit the file by replacing its content with the following
Host github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
Now if you are on Mac operating systems you can run the following command to store your passphrase into a keychain
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
Adding GPG and SSH Key to GitHub Profile
In this section, we will go through how you can add either GPG or SSH Key to the GitHub Profile.
- On the top right of GitHub click on profile.
- Click on setting and navigate to the “Access” section
- Click on “SSH and GPG keys”
- Click either “New SSH Key” or “New GPG Key”
- If you are adding new GPG Key copy and paste the PUBLIC KEY BLOCK into the text box and save as new GPG Key. If you are adding new SSH key use the following command in terminal to get the key
pbcopy < ~/.ssh/id_ed25519.pub
and add it into the SSH key text box.
This article shows you how to add GPG and SSH Key so you can fork a repository to complete a Pull Request. If you are curious on how to make a pull request, please use this following link here.