How to fix npm ERR! git clone git@github.com:user/repo.git failed npm ERR! Permission denied (publickey) in npm

npmINTERMEDIATEMEDIUMUpdated Dec 7, 2025· 381 views

This error occurs when npm tries to clone a Git dependency using SSH but your SSH key isn't configured or recognized. Common in CI/CD environments, new machines, or when using the wrong SSH key.

Quick fix

Fixes npm ERR! git clone git@github.com:user/repo.git failed npm ERR! Permission denied (publickey)

ls -la ~/.ssh/

# Look for id_rsa/id_rsa.pub or id_ed25519/id_ed25519.pub
  1. Check if SSH keys exist
  2. Add SSH key to ssh-agent
  3. Add public key to GitHub/GitLab
  4. Test SSH connection
npm — error
ls -la ~/.ssh/
# Look for id_rsa/id_rsa.pub or id_ed25519/id_ed25519.pub
npm ERR! git clone git@github.com:user/repo.git failed
npm ERR! Permission denied (publickey)

What this error means

When your package.json contains a Git dependency using SSH syntax (like `git@github.com:user/repo.git`), npm needs SSH authentication to clone the repository. This error means SSH authentication failed—typically because no SSH key is available or the key isn't authorized for the repository. This is one of the most common issues when: - Setting up a new development machine - Running npm install in CI/CD pipelines - Working with private repositories - The SSH agent isn't running or doesn't have your key loaded

Typical symptoms

  • npm install fails with 'Permission denied (publickey)'
  • Error shows 'git clone git@github.com:...' failed
  • Works on some machines but not others
  • Fails in CI/CD but works locally
  • Error code 128 from git

Common causes

  1. SSH key not generated on this machine
  2. SSH key not added to GitHub/GitLab account
  3. SSH agent not running or key not loaded
  4. SSH key has a passphrase (npm can't prompt for it)
  5. Using wrong SSH key for the repository
  6. CI/CD environment doesn't have SSH key configured

How to fix "npm ERR! git clone git@github.com:user/repo.git failed npm ERR! Permission denied (publickey)"

1Check if SSH keys exist

First, verify you have SSH keys:

bash
ls -la ~/.ssh/

# Look for id_rsa/id_rsa.pub or id_ed25519/id_ed25519.pub

If no keys exist, generate one:

bash
ssh-keygen -t ed25519 -C "your_email@example.com"
2Add SSH key to ssh-agent

Start the SSH agent and add your key:

bash
# Start ssh-agent
eval "$(ssh-agent -s)"

# Add your key
ssh-add ~/.ssh/id_ed25519
# Or for RSA keys:
ssh-add ~/.ssh/id_rsa

# Verify key is loaded
ssh-add -l
3Add public key to GitHub/GitLab

Copy your public key and add it to your Git hosting service:

bash
# Copy public key to clipboard (macOS)
cat ~/.ssh/id_ed25519.pub | pbcopy

# Or display it to copy manually
cat ~/.ssh/id_ed25519.pub

Then:
1. Go to GitHub → Settings → SSH and GPG keys
2. Click "New SSH key"
3. Paste your public key and save

4Test SSH connection

Verify SSH authentication works:

bash
ssh -T git@github.com

# Expected output:
# Hi username! You've successfully authenticated...

If this fails, the key isn't properly configured.

5Use HTTPS instead of SSH (quick workaround)

If you can't configure SSH, switch to HTTPS:

bash
# Configure git to use HTTPS instead of SSH
git config --global url."https://github.com/".insteadOf "git@github.com:"

# Or update package.json to use HTTPS URL
json
{
  "dependencies": {
    "my-package": "git+https://github.com/user/repo.git"
  }
}

Advanced notes

CI/CD Configuration:

For GitHub Actions:

yaml
- uses: webfactory/ssh-agent@v0.8.0
  with:
    ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- run: npm ci

Passphrase-Protected Keys: npm cannot prompt for SSH key passphrases. Either use a key without a passphrase (for automation) or ensure your ssh-agent has the key loaded.

Windows: Ensure OpenSSH Authentication Agent service is running:

powershell
Get-Service ssh-agent | Set-Service -StartupType Automatic
Start-Service ssh-agent

Multiple SSH Keys: If you have multiple keys, create ~/.ssh/config:

bash
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_key

Frequently asked questions

What does "npm ERR! git clone git@github.com:user/repo.git failed npm ERR! Permis" mean?
git), npm needs SSH authentication to clone the repository. This error means SSH authentication failed—typically because no SSH key is available or the key isn't authorized for the repository.
How do I fix "npm ERR! git clone git@github.com:user/repo.git failed npm ERR! Permis"?
This error occurs when npm tries to clone a Git dependency using SSH but your SSH key isn't configured or recognized. Common in CI/CD environments, new machines, or when using the wrong SSH key.
What causes "npm ERR! git clone git@github.com:user/repo.git failed npm ERR! Permis"?
SSH key not generated on this machine SSH key not added to GitHub/GitLab account SSH agent not running or key not loaded
Is the "npm ERR! git clone git@github.com:user/repo.git failed npm ERR! Permis" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading