Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
Git

Git: Fix ‘Permission Denied (publickey)’ When Everything Worked Yesterday

- 05.09.26 - ErcanOPAK

🔀 The Same SSH Setup That Worked Yesterday Suddenly Says Permission Denied

git pull or git push over SSH, which worked without any issue yesterday, suddenly fails with ‘Permission denied (publickey)’ today – no changes were made to SSH keys, no new machine, nothing about the local setup was touched, and yet Git refuses to authenticate.

🐞 The Problem

$ git pull origin main
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

🔍 Why This Happens

This almost always traces back to something changing on either the
KEY side or the AGENT side, even without deliberate action: an
SSH agent that lost its loaded keys after a reboot or a long sleep
(keys added with ssh-add are often NOT persisted across a restart
unless explicitly configured to be), an expired or revoked deploy
key/access token on the git hosting side, or - less obviously - a
system clock significantly out of sync, which can cause some SSH
key exchange methods to fail validation.

✅ The Fix: Confirm the Agent Actually Has the Key Loaded, Then Check the Remote Side

  • Run ssh-add -l to list keys currently loaded in the SSH agent – if it shows ‘The agent has no identities,’ the key was never reloaded after a restart, and simply running ssh-add ~/.ssh/id_ed25519 (or your key’s path) again resolves it immediately.
  • Test the connection directly and verbosely: ssh -vT git@github.com – this shows exactly which key (if any) is being offered and why the server rejects it, which is far more informative than Git’s own generic error.
  • Check the hosting platform’s SSH key settings (GitHub/GitLab/Bitbucket) to confirm the key hasn’t been removed, expired, or flagged – a key that was valid yesterday can be revoked by an admin, a security policy, or its own configured expiration without any local change at all.

⚠️ Making the Fix Stick Across Reboots

  • Configure your SSH client to auto-load keys via a config entry (AddKeysToAgent yes in ~/.ssh/config, or your OS’s keychain integration) so this exact ‘works today, fails after a restart’ cycle stops recurring.
  • If multiple keys exist for different services, confirm the right one is actually being offered for this specific host – an SSH config with explicit IdentityFile entries per host avoids ambiguity when several keys are loaded at once.

Nothing about your setup necessarily broke — SSH authentication depends on a chain of things (agent state, key validity, server-side trust) that can each quietly reset on their own, and the fix is almost always just reconnecting one link in that chain.

— Version Control Tip

Related posts:

Git: Resolve Merge Conflicts Like a Pro

Git: Use git reflog to Recover Lost Commits After Reset

Git: Use git revert Instead of git reset for Shared Branches

Post Views: 3

Post navigation

The AI Prompt That Explains Exactly What a Rental or Service Contract Obligates You To Before You Sign
Ajax: Fix Duplicate Requests Fired by a Button Wired to Two Event Listeners at Once

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

October 2026
M T W T F S S
 1234
567891011
12131415161718
19202122232425
262728293031  
« Sep    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (952)
  • How to add default value for Entity Framework migrations for DateTime and Bool (939)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (837)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (624)
  • Add Constraint to SQL Table to ensure email contains @ (590)
  • Average of all values in a column that are not zero in SQL (553)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (526)
  • Find numbers with more than two decimal places in SQL (468)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps
  • Photoshop: Fix a Color Profile Mismatch That Makes Printed Output Look Nothing Like What You Saw On Screen
  • WordPress: Fix Search Results That Return Pages From a Theme You Deactivated Months Ago
  • Visual Studio: Fix a Test Project That Builds Fine Alone but Fails to Discover Any Tests After a NuGet Restore
  • ASP.NET Core: Fix a File Upload That Times Out on Slow Connections Only Because Kestrel’s Minimum Data Rate Feature Kicked In
  • JavaScript: Fix an Array Destructuring Default Value That Silently Never Applies Because null Was Passed Instead of Undefined

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (973)
  • How to make theater mode the default for Youtube (952)
  • How to add default value for Entity Framework migrations for DateTime and Bool (939)
  • Get the First and Last Word from a String or Sentence in SQL (847)
  • How to select distinct rows in a datatable in C# (837)

Recent Posts

  • CSS: Fix a prefers-color-scheme Media Query That Gets Silently Overridden by a Browser Extension’s Forced Dark Mode
  • Git: Fix a Merge Commit That Silently Drops a File Because Both Branches Deleted It Differently
  • HTML5: Fix a Native Lazy-Loading Image That Never Loads Because It Sits Inside a Hidden Tab Until the User Clicks It
  • The AI Prompt That Traces a Null Reference Exception Back to the Exact Line That First Produced the Null
  • The AI Prompt That Turns a Gym Membership Contract’s Fine Print Into a Plain-English List of Cancellation Steps

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com