惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
H
Help Net Security
小众软件
小众软件
N
Netflix TechBlog - Medium
C
Check Point Blog
量子位
Last Week in AI
Last Week in AI
GbyAI
GbyAI
Martin Fowler
Martin Fowler
M
MIT News - Artificial intelligence
博客园 - 聂微东
Engineering at Meta
Engineering at Meta
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
D
DataBreaches.Net
Project Zero
Project Zero
P
Proofpoint News Feed
T
Threat Research - Cisco Blogs
Security Latest
Security Latest
Cisco Talos Blog
Cisco Talos Blog
Recorded Future
Recorded Future
I
Intezer
L
Lohrmann on Cybersecurity
Cyberwarzone
Cyberwarzone
博客园_首页
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
P
Palo Alto Networks Blog
V
V2EX
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
The Exploit Database - CXSecurity.com
The Hacker News
The Hacker News
Blog — PlanetScale
Blog — PlanetScale
G
GRAHAM CLULEY
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
The Register - Security
The Register - Security
L
LINUX DO - 热门话题
P
Privacy & Cybersecurity Law Blog
Scott Helme
Scott Helme
F
Full Disclosure
博客园 - 司徒正美
Recent Announcements
Recent Announcements
IT之家
IT之家
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Attack and Defense Labs
Attack and Defense Labs
Cloudbric
Cloudbric
Help Net Security
Help Net Security
The Last Watchdog
The Last Watchdog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
How to Set Up SSH & GPG Signed Commits on GitHub to Block Force-Push Attacks
Ankush Lokhande · 2026-06-01 · via DEV Community

👋 Hey all,
Welcome back to our blog!

Here's a scary thought:

Someone force-pushes to main.
Git history gets rewritten.
A malicious commit appears in the branch.

Nobody notices that the commit wasn't created by the developer it claims to be from.

This isn't just a theoretical risk. Misconfigured repositories, compromised accounts, and unverified commits can make it difficult to trust the history of your codebase.

Today, we're setting up two important layers of Git security that many developers overlook: SSH authentication and GPG commit signing.

Together, they help ensure:

✅ Only authorized machines can authenticate with GitHub using your SSH key
✅ Every commit is cryptographically signed and can be verified
✅ Rewritten history and suspicious commits become much easier to detect
✅ GitHub displays a Verified badge for authentic signed commits

Let's Begin

In this guide, we'll walk through the complete setup on macOS — from installing GitHub CLI and configuring SSH access to generating a GPG key and signing every commit you create.

Let's lock down our Git workflow. 🔐

Prerequisites

  • Mac with Homebrew installed
  • GitHub account
  • Terminal access

Setup Prerequisites

Configure SSH Authentication & GPG Signed Commits on GitHub

SSH authentication secures access to your GitHub repositories, while GPG signing verifies the authenticity of every commit you create. Together, they help protect your codebase and build trust in your Git history.

Start Coding

Step 1 — Install GitHub CLI

Run command to download gh:

brew install gh

gh is GitHub's official command-line tool. It allows you to authenticate with GitHub, generate SSH keys, and manage repositories directly from your terminal.

Step 2 — SSH Setup

Run:

gh auth login

Answer the following:

? Where do you use GitHub?
  GitHub.com
? What is your preferred protocol for Git operations on this host?
  SSH
? Generate a new SSH key to add to your GitHub account?
  Yes
? Enter a passphrase for your new SSH key (Optional)
  ********
? Title for your SSH key
  title_for_ssh_key // eg. organization_name
? How would you like to authenticate GitHub CLI?
  Login with a web browser

GitHub CLI will then display a one-time code:

! First copy your one-time code: XXXX-XXXX
Press Enter to open https://github.com/login/device in your browser...

Press Enter, open the provided URL, sign in to your GitHub account, and enter the one-time code when prompted.

After successful authentication, you'll see output similar to:

✓ Authentication complete.
✓ Configured git protocol
✓ Uploaded the SSH key to your GitHub account
✓ Logged in as your-username

This step automatically generates a new SSH key, uploads it to your GitHub account, and configures Git to use SSH for repository operations.

Step 3 — Install GnuPG

Run the following command:

brew install gnupg

Verify the installation:

gpg --version

GnuPG (GPG) is used to generate cryptographic keys that digitally sign your commits. GitHub uses these signatures to verify that a commit was created by you and has not been modified since it was signed.

Step 4 — Generate a GPG Key

Run:

gpg --full-generate-key

Select the following options:

Please select what kind of key you want:
(1) RSA and RSA

RSA keys may be between 1024 and 4096 bits long.
What keysize do you want?
4096

Please specify how long the key should be valid.
0 = key does not expire

Real name:
Your Name

Email address:
your-email@example.com

Review the information and confirm the key creation.

You'll then be prompted to create a passphrase for your key.

Choose a strong passphrase and store it securely. This passphrase protects your private GPG key and will be required when signing commits.

Step 5 — Find Your GPG Key ID

Run:

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

Example output:

sec   rsa4096/ABC123DEF4567890 2026-06-01 [SC]
      1234567890ABCDEF1234567890ABCDEF12345678
uid                 [ultimate] Your Name <your-email@example.com>

Copy the value after rsa4096/:

ABC123DEF4567890

This is your GPG Key ID. You'll use it to export your public key and configure Git commit signing.

Step 6 — Export Your Public GPG Key

Replace <KEY_ID> with the key ID copied in the previous step:

gpg --armor --export <KEY_ID>

Example:

gpg --armor --export ABC123DEF4567890

You'll see output similar to:

-----BEGIN PGP PUBLIC KEY BLOCK-----
...
-----END PGP PUBLIC KEY BLOCK-----

Copy the entire block, including the BEGIN and END lines.

This is your public GPG key. GitHub uses it to verify commits signed with your private key.

Step 7 — Add Your GPG Key to GitHub

Open GitHub and navigate to:

Profile Picture → Settings → SSH and GPG Keys

Click:

New GPG Key

Paste the public key copied in the previous step:

-----BEGIN PGP PUBLIC KEY BLOCK-----
...
-----END PGP PUBLIC KEY BLOCK-----

Then click Add GPG Key.

Once added, GitHub can verify commits signed with your private GPG key and display the Verified badge on your commits.

Step 8 — Configure Git to Sign Commits

Replace <KEY_ID> with your GPG Key ID and run:

git config --global user.signingkey <KEY_ID>
git config --global commit.gpgsign true
git config --global gpg.program gpg

Example:

git config --global user.signingkey ABC123DEF4567890
git config --global commit.gpgsign true
git config --global gpg.program gpg

These settings tell Git which GPG key to use and automatically sign every commit you create.

Step 9 — Configure GPG Terminal Support

Run:

echo 'export GPG_TTY=$(tty)' >> ~/.zshrc
source ~/.zshrc

This allows GPG to interact correctly with your terminal when requesting your passphrase during commit signing.

Step 10 — Verify Commit Signing

Create a signed commit:

git commit -S -m "Test signed commit"

If prompted, enter the passphrase you created when generating your GPG key.

Push the commit to GitHub:

git push

Open the commit on GitHub. You should see a Verified badge next to the commit.

Verified Commit Example

The Verified badge confirms that GitHub successfully validated the GPG signature attached to your commit.

Step 11 — Protect Your Main Branch

For maximum security, enable branch protection rules on your repository.

Navigate to:

Repository → Settings → Branches

Edit your branch protection rule and enable:

✓ Require signed commits
✓ Block force pushes
✓ Require pull request reviews
✓ Require status checks before merging

These protections help ensure that only verified, reviewed, and trusted code can be merged into your main branch.


Let's Wrap!

SSH authentication protects repository access, while GPG signing verifies commit authenticity. Together, they provide a stronger security foundation for your Git workflow and make suspicious or rewritten commits much easier to identify. 🔐

One correction: GitHub doesn't literally have a setting called "Block force pushes" everywhere. Depending on the repository type, you'll typically see "Allow force pushes" (leave disabled) or "Restrict who can force push". So for accuracy, you may want to write:

✓ Require signed commits
✓ Disable force pushes
✓ Require pull request reviews
✓ Require status checks before merging

which is easier for readers to understand.

Thanks for reading

If you found this blog helpful or have any further questions, we would love to hear from you. Feel free to reach out and follow us on our social media platforms for more tips and tutorials on tech-oriented posts.

Happy coding!👨‍💻