هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
Know it before you install
Gitleaks checks text against rules (regular expressions + entropy + keywords) for 150+ secret types (AWS keys, GitHub tokens, Slack webhooks, private keys …). Each finding has a fingerprint (commit:file:rule:line) you can use to mark a reviewed false positive.
| Item | Value |
|---|---|
| Program | gitleaks (one binary) |
| Commands | gitleaks git (Git history), gitleaks dir (files), gitleaks stdin |
| Config | .gitleaks.toml in the repo (extends the default rules) |
| Ignore list | .gitleaksignore (fingerprints of reviewed false positives) |
| Reports | --report-format json/sarif/csv --report-path FILE |
Install on RHEL and Ubuntu
Choose the version from github.com/gitleaks/gitleaks/releases:
GVER=8.28.0
curl -fsSLO https://github.com/gitleaks/gitleaks/releases/download/v$GVER/gitleaks_${GVER}_linux_x64.tar.gz
tar -xzf gitleaks_${GVER}_linux_x64.tar.gz gitleaks
install -m 0755 gitleaks /usr/local/bin/gitleaks
gitleaks versionOr the container: docker run --rm -v "$PWD":/repo zricethezav/gitleaks:v8.28.0 git /repo.
First configuration: scan a repository
Scan the whole history (secrets deleted in later commits are still in Git):
cd my-project
gitleaks git -v --redact
Finding: aws_secret_access_key = "REDACTED"
Secret: REDACTED
RuleID: aws-access-token
File: deploy/old-config.env
Commit: 3f9c2a1…
Fingerprint: 3f9c2a1…:deploy/old-config.env:aws-access-token:4
4:21PM WRN leaks found: 1
gitleaks dir . --redact
gitleaks git --report-format sarif --report-path gitleaks.sarif--redact hides the secret value in the output (important in CI logs).
Your own rules and allow lists, on top of the default rules:
[extend]
useDefault = true
[[rules]]
id = "shop-internal-token"
description = "Internal shop API token"
regex = '''shop_tok_[A-Za-z0-9]{32}'''
keywords = ["shop_tok_"]
[allowlist]
description = "Test fixtures and docs examples"
paths = [
'''tests/fixtures/''',
'''docs/examples/''',
]
regexes = [
'''AKIAIOSFODNN7EXAMPLE''',
]A reviewed false positive goes into .gitleaksignore by fingerprint (one per line).
Stop secrets before the commit
With the pre-commit framework (works for the whole team):
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.28.0
hooks:
- id: gitleakspipx install pre-commit
pre-commit install
git commit -m "Add config"
Detect hardcoded secrets.................................................FailedOr a plain Git hook: gitleaks git --pre-commit --staged --redact in .git/hooks/pre-commit.
A CI job
Run it on every push and pull request (here GitLab CI; GitHub Actions and Jenkins work the same with the binary or container):
secrets-scan:
stage: test
image:
name: zricethezav/gitleaks:v8.28.0
entrypoint: [""]
variables:
GIT_DEPTH: 0
script:
- gitleaks git --redact --report-format sarif --report-path gitleaks.sarif .
artifacts:
when: always
paths: [gitleaks.sarif]GIT_DEPTH: 0 gives the full history. (The official GitHub Action needs a license key for organization accounts; running the binary or container needs none.)
Daily use and when a secret leaked
gitleaks git --log-opts="--since=2026-11-01" --redact
gitleaks git --log-opts="main..feature-x" --redact
gitleaks dir ./config --redact
cat app.log | gitleaks stdin --redact
gitleaks git --baseline-path gitleaks-baseline.json --redact--baseline-path reports only new findings compared to an older report — useful when you start on an old repository.
انتبه
When a real secret is found, the order is: 1) revoke and rotate it at the provider at once, 2) check its logs for misuse, 3) then clean the history (git filter-repo) if needed, and 4) add a rule or hook so it does not happen again. Deleting the file in a new commit does not remove the secret.
Real uses at work:
- Pre-commit hooks for all developers; a CI gate on every merge request.
- One-time scans of old repositories before making them public.
- Scanning config folders, logs and backups for credentials.
Make it safe
Security checklist:
- Scan full history once, then every commit (hook + CI).
--redactin CI so reports do not leak the secrets again; keep reports private.- Allow lists are narrow (paths for test fixtures), reviewed in pull requests.
- Rotate first, clean later; use a secret manager (Vault, SOPS, cloud secrets) so secrets are not in code.
- Pin the Gitleaks version; add custom rules for your internal token formats.
Update and remove
Download the new release and replace the binary; update rev in .pre-commit-config.yaml (pre-commit autoupdate). Remove: rm /usr/local/bin/gitleaks, pre-commit uninstall.
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
Unknown command detect / protect warnings | Old commands from v8 before 8.19. | Use gitleaks git (history) and gitleaks dir (files). |
| CI finds nothing in old commits | Shallow clone. | Fetch full history (GIT_DEPTH: 0, fetch-depth: 0). |
| Many false positives in tests or docs | Example keys look real. | Allowlist those paths/regexes; add fingerprints to .gitleaksignore. |
| Very slow on a huge repository | Scanning all history every time. | Limit with --log-opts (only new commits) and a baseline. |
| The hook does not run | pre-commit install was not run in this clone. | Run it; for the team, also enforce in CI. |
Next steps
- Quick how-tos: Find secrets with Gitleaks, Remove a secret from Git history.
- Command page: gitleaks.
- Git security: Keep secrets out of Git, Scan for secrets, React to a leaked secret.
- At work: Gitleaks — find secrets in Git. Store secrets properly: Vault.
1You deleted a leaked password in a new commit. Is the leak fixed?
No. It is still in the Git history — rotate the password first.
2Why use --redact in CI?
So the secret value does not appear again in the CI log or report.