Gitleaks in Termux – Scan Git Repositories for Secrets

Gitleaks is a simple security tool that checks your code for exposed secrets and can find passwords, API keys, tokens, and other sensitive information inside files and Git repositories. Gitleaks runs from the command line and works well on Linux and Termux and is useful for checking your projects before sharing or uploading them.

Here’s what you can do with Gitleaks in Termux:

  • Scan Git repositories for exposed secrets.
  • Scan files and directories for sensitive information.
  • Detect API keys, passwords, tokens, and other secrets.
  • Create reports in different formats.
  • Use custom configuration files.
  • Control which detection rules are enabled.
  • Hide detected secrets from scan output.

Install Gitleaks in Termux

Below are the commands to install Gitleaks in Termux, just copy and run them one by one in the terminal.

First, update the Termux packages.

pkg update && pkg upgrade -y

Install Git, Go, and Make.

pkg install git golang make -y

Clone the Gitleaks repository.

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

Go to the Gitleaks directory.

cd gitleaks

Build Gitleaks.

make build

Add the Gitleaks binary to the Termux PATH.

mv gitleaks $PREFIX/bin/

Check the installed Gitleaks version.

gitleaks version

If the version is displayed, Gitleaks has been installed successfully.

Gitleaks Usage Commands

After installing Gitleaks you can start checking your files and projects for exposed secrets using the useful commands below.

Use gitleaks dir to scan a directory or files for secrets.

gitleaks dir .

You can specify a directory:

gitleaks dir /path/to/directory

Use gitleaks git to scan a Git repository.

gitleaks git .

You can also scan a Git repository by providing its path:

gitleaks git /path/to/repository

Scan the current directory without using Git history.

 gitleaks detect --no-git -v

Use gitleaks stdin to scan data provided through the terminal.

echo "example data" | gitleaks stdin

Use verbose output to display more information during a scan.

gitleaks dir . -v

Disable the Gitleaks banner.

gitleaks dir . --no-banner

Disable colored output.

gitleaks dir . --no-color

Save scan results to a JSON file.

gitleaks dir . -f json -r report.json

Save scan results as a CSV file.

gitleaks dir . -f csv -r report.csv

Save scan results as a SARIF report.

gitleaks dir . -f sarif -r report.sarif

Use a custom configuration file.

gitleaks dir . -c .gitleaks.toml

Use a baseline file to ignore previously identified issues.

gitleaks dir . -b baseline.json

Use a .gitleaksignore file.

gitleaks dir . -i .gitleaksignore

Redact detected secrets from the output.

gitleaks dir . --redact

You can also partially redact detected secrets. For example:

gitleaks dir . --redact=20

Show the available commands and options.

gitleaks --help

Show help for a specific command:

gitleaks dir --help

Check the installed version:

gitleaks version

Gitleaks supports several commands:

completion
dir
git
help
stdin
version

These commands cover the basic Gitleaks options you can use to scan your files and projects for exposed secrets.

End Note

Gitleaks is a useful tool for finding passwords, API keys, tokens and other secrets in your projects and you can use it to check your own files and repositories before sharing them online and remove any sensitive information before publishing your code or project.

SHARE THIS POST: