Git Update Failed Permission Denied Publickey [Solved]

Immediate Fix

The “Permission denied (publickey)” error occurs when your local machine fails to authenticate with the remote Git server. Follow these steps to resolve it quickly.

Step 1: Verify Existing SSH Keys

Check if you already have an SSH key generated on your system. Run the following command in your terminal:

ls -al ~/.ssh

If you don’t see files like id_rsa.pub or id_ed25519.pub, you need to generate a new one.

Step 2: Generate and Add a New SSH Key

Use the following commands to create a key and add it to your authentication agent:

Task Command
Generate Key
ssh-keygen -t ed25519 -C "[email protected]"
Start Agent
eval "$(ssh-agent -s)"
Add Private Key
ssh-add ~/.ssh/id_ed25519

Step 3: Upload Public Key to Git Provider

Copy your public key to your clipboard:

cat ~/.ssh/id_ed25519.pub

Go to your Git provider (GitHub, GitLab, or Bitbucket) settings, navigate to “SSH and GPG keys,” and paste the copied text into a new SSH key entry.

Technical Explanation

Git uses the SSH (Secure Shell) protocol for encrypted communication between your computer and the remote repository. This process relies on a pair of cryptographic keys: a private key (stored locally) and a public key (uploaded to the server).

The “Permission denied (publickey)” error triggers when the server asks for your identity, but your local Git client cannot provide a private key that matches any public key registered on the server side.

Common causes include missing keys, an inactive SSH agent, or using the wrong SSH key for a specific repository. It can also happen if your remote URL is configured for SSH, but you have only set up HTTPS credentials.

Troubleshooting git update failed permission denied publickey error on a computer screen.

Alternative Methods

Method 1: Switch to HTTPS

If you cannot resolve SSH issues, you can switch the remote URL to HTTPS. This will prompt you for a Personal Access Token (PAT) instead of SSH keys.

git remote set-url origin https://github.com/username/repository.git

Method 2: Use an SSH Config File

If you use multiple Git accounts, create a config file to specify which key to use for which host.

nano ~/.ssh/config

Add the following configuration:

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519

Method 3: Test the Connection

Verify if the connection works without performing a full Git operation by running:

ssh -T [email protected]