Skip to content

Techeons

Imagine | Explore | Innovate

Menu
  • Home
Menu

How to scan and remove secrets such as API keys and passwords from your git repo

Posted on September 2, 2024

Gitleaks – Scan for secrets

https://github.com/gitleaks/gitleaks

BFG Repo Cleaner Tool

Download the tool from: https://rtyley.github.io/bfg-repo-cleaner

Setup alias for the BFG tool:

alias bfg="java -jar /xyz/bfg.jar"

To remove secrets completely:

Replace all secrets listed in a file (prefix lines ‘regex:’ or ‘glob:’ if required) with ***REMOVED*** wherever they occur in your repository :

$ bfg --replace-text secrets.txt
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive
$ git push -f

To remove false positives:

1) Use .gitleaksignore <– This did not work for me

2) Use #gitleaks:allow

For 2), in your secrets.txt have it as “xyz”==>”xyz” #gitleaks:allow i.e. SEARCH==>REPLACE format.

$ bfg --replace-text secrets.txt
$ git reflog expire --expire=now --all && git gc --prune=now --aggressive
$ git push -f

Share on Social Media
x facebook pinterest linkedin tumblr reddit emailwhatsapptelegrammastodon

Leave a Reply Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Nginx: How to increase timeout for Nginx
  • Cheat Sheet: Essential Git Commands
  • Setting a default shell in Linux
  • Setting up Composer on Linux
  • Switch easily between Python versions on a Mac using pyenv

Tags

ai alerting aws b2 backblaze certificate cheatsheet cloud commands data-science datalake devops dns docker dremio git gitlab infra jenkins kubernetes linux metabase minikube minio monitoring mount mysql nginx nodejs notebooks openssh php python scala secrets spark ssh ssl ubuntu ufw usb web dev tools windows xampp zeppelin

©2026 Techeons | Design: Newspaperly WordPress Theme