Install Gitleaks on Ubuntu 24.04

Install Gitleaks on Ubuntu 24.04

Gitleaks is an open-source tool designed to scan Git repositories for secrets and other sensitive information. It helps developers and organizations ensure that they are not inadvertently committing sensitive data such as passwords, API keys, tokens, and other confidential information into their code repositories. This tutorial explains how to install Gitleaks on Ubuntu 24.04.

Install Gitleaks

Fetch the newest Gitleaks version from the GitHub repository and store it in a variable:

GITLEAKS_VERSION=$(curl -s "https://api.github.com/repos/gitleaks/gitleaks/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')

Download Gitleaks using the previously identified version:

wget -qO gitleaks.tar.gz https://github.com/gitleaks/gitleaks/releases/latest/download/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz

Extract executable to /usr/local/bin directory:

sudo tar xf gitleaks.tar.gz -C /usr/local/bin gitleaks

We can check Gitleaks version as follows:

gitleaks version

Remove downloaded archive:

rm -rf gitleaks.tar.gz

Testing Gitleaks

For testing purpose, clone the repository:

git clone https://github.com/gitleaks/gitleaks

Then, run the following command to scan the cloned repository for secrets:

gitleaks detect --source gitleaks -v

This command scans the gitleaks directory for any sensitive information, with the -v flag providing verbose output for detailed results. Output example:

    ○
    │╲
    │ ○
    ○ ░
    ░    gitleaks

Finding:     ...OUDFLARE_ORIGIN_CA: v1.0-aaa334...`
Secret:      v1.0-aaa334...
RuleID:      cloudflare-origin-ca-key
Entropy:     4.044857
File:        cmd/generate/config/rules/cloudflare.go
Line:        20
Commit:      821b2323940b1792d9001d0812a2a4f7480a69c0
Author:      John
Email:       john@example.com
Date:        2024-04-29T18:44:19Z
Fingerprint: 821b2323940b1792d9001d0812a2a4f7480a69c0:cmd/generate/config/rules/cloudflare.go:cloudflare-origin-ca-key:20

...

7:35AM INF 852 commits scanned.
7:35AM INF scan completed in 552ms
7:35AM WRN leaks found: 38

Uninstall Gitleaks

To remove Gitleaks, delete the associated file:

sudo rm -rf /usr/local/bin/gitleaks

Leave a Comment

Cancel reply

Your email address will not be published.