How to setup verified commits on GitHub
Tags: git, github, frontend, backend
Published: 2024-04-21 21:46:36

---
title: How to setup verified commits on GitHub
published: true
date: 2024-04-21 20:22:43 UTC
tags: git, github, frontend, backend
cover_image: https://www.luisfalconmx.dev/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1713730847621%2F0d6ef644-38ee-4444-8033-f3ee7fbbd6bc.jpeg&w=1920&q=75
canonical_url: https://www.luisfalconmx.dev/blog/how-to-setup-verified-commits-on-github
---

In the world of software development, maintaining the integrity and authenticity of code is paramount. One effective way to enhance this security is through verified commits using GPG (GNU Privacy Guard). In this comprehensive guide, we'll explore the steps involved in setting up verified commits, providing you with a solid foundation for ensuring the trustworthiness of your codebase.

Verified commits are particularly valuable for open-source projects and collaborations where multiple contributors are involved. By leveraging GPG, developers can cryptographically sign their commits, establishing a clear chain of trust and safeguarding against unauthorized changes.

In this post, we'll cover everything you need to know, from installing and configuring GPG to signing your commits and understanding the verification process. Whether you're new to cryptographic signatures or seeking to enhance your project's security, this guide will walk you through the essential steps, demystifying the process along the way.

## Creating GPG Keys

First, you need to generate a GPG Key pair. Your GPG Key must use RSA with a key size of 4096 bits.

```
gpg --full-generate-key
```

At the prompt, specify the kind of key you want, or press Enter to accept the default RSA.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713727126910/202563b7-874a-47ea-b83f-f2c1e59e58da.png)

Enter the desired key size. I recommend the maximum key size of `4096`.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713727540729/ac5465fd-267f-4150-a7b0-ddcc75bb8b03.png)

Enter the length of time the key should be valid. Press Enter to specify the default selection, indicating that the key doesn't expire.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713727594189/10bc0bb3-bc7c-4539-99ed-66e445ca4fcc.png)

Verify that your selections are correct and enter your user ID information.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713727808899/41df4a67-b4ad-42c6-88ae-9c47e1b606be.png)

Type a secure passphrase. Remember, you need to use this phrase on each commit created or when trying to use a SSH operation.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713727890980/3b992d32-85c8-4249-93b8-01b3fe227616.png)

Use the `gpg --list-secret-keys --keyid-format LONG` command to list GPG keys for which you have both a public and private key. A private key is required for signing commits or tags. From the list of GPG keys, copy the GPG key ID you'd like to use. In this example, the GPG key ID is `6D1879875E68B0B1`

```
gpg --list-secret-keys --keyid-format LONG
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713728037985/d982ae45-794c-4b33-8bf6-61c833099c73.png)

Paste the text below, substituting in the GPG key ID you'd like to use. In this example, the GPG key ID is `6D1879875E68B0B1`

```
gpg --armor --export 6D1879875E68B0B1
```

Copy your GPG key, beginning with `-----BEGIN PGP PUBLIC KEY BLOCK-----` and ending with `-----END PGP PUBLIC KEY BLOCK-----`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713728211397/a89597ea-129f-4190-948a-1f245d5ef971.png)

## Adding a new GPG key to your GitHub account

In the upper-right corner of any page, click your profile photo, then click Settings.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713728602060/eef55923-7629-4804-954f-dada0816d038.png)

Click on **SSH and GPG keys** and add new GPG key.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713728889615/7dff55f7-85ac-4833-903c-97c5a5e368cd.jpeg)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713729002066/becd114a-8b40-4587-9ae7-be27cd223caa.png)

In the "Key" field, paste the GPG key you copied when you generated your GPG key

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713729177285/cef49d08-dca4-498f-be3e-e0bba3b9a122.png)

To finish, click on add GPG key and confirm the action with your GitHub password or your preferred auth method.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713729224004/05b49839-a24d-4564-995d-26e6bbe56c8d.png)

## Getting GPG Keys

Open your terminal and use the `gpg --list-secret-keys --keyid-format LONG` command to list GPG keys for which you have both a public and private key. A private key is required for signing commits or tags. From the list of GPG keys, copy the GPG key ID you'd like to use. In this example, the GPG key ID is `6D1879875E68B0B1`:

```
gpg --list-secret-keys --keyid-format LONG
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1713729467147/fa152833-ffae-4503-8a01-d21af092958d.png)

## Git Settings

To set your GPG signing key in Git, paste the text below, substituting in the GPG key ID you'd like to use. In this example, the GPG key ID is `6D1879875E68B0B1`:

```
git config --global user.signingkey 6D1879875E68B0B1
```

To tell git to automatically sign commits you can set:

```
git config --global commit.gpgsign true
```

If you use Ubuntu you need to add the next line in your `~/.bashrc` file.

```
# .bashrcexport GPG_TTY=$(tty)
```

## Conclusion

Implementing verified commits using GPG is a proactive step towards enhancing the security and trustworthiness of your codebase. By adopting this practice, you not only protect your project from unauthorized changes but also contribute to a more transparent and accountable development process.

Throughout this guide, we've covered the essential steps for setting up and using GPG to sign commits effectively. Remember, verified commits not only benefit open-source projects but can also be valuable for teams working on proprietary software, ensuring that each commit is attributable and tamper-proof.