How to fix npm ERR! git clone git://github.com/user/private-repo.git failed npm ERR! fatal: Authentication failed in npm

npmINTERMEDIATEHIGHUpdated Dec 7, 2025· 245 views

npm fails to install dependencies from private Git repositories when it cannot authenticate with the remote server. This occurs when the system lacks valid credentials (SSH keys, personal access tokens, or cached credentials) to access the remote repository.

Quick fix

Fixes npm ERR! git clone git://github.com/user/private-repo.git failed npm ERR! fatal: Authentication failed

# For SSH access
ssh -T git@github.com

# For HTTPS access
git clone https://github.com/owner/private-repo.git
  1. Verify the repository is accessible manually
  2. Set up SSH authentication (for local development)
  3. Create and configure a GitHub Personal Access Token (HTTPS)
  4. Handle CI/CD environment authentication
npm — error
# For SSH access
ssh -T git@github.com
# For HTTPS access
git clone https://github.com/owner/private-repo.git
npm ERR! git clone git://github.com/user/private-repo.git failed
npm ERR! fatal: Authentication failed

What this error means

npm fails to install dependencies from private Git repositories when it cannot authenticate with the remote server. This occurs when npm invokes git clone to fetch packages specified in package.json, but the system lacks valid credentials (SSH keys, personal access tokens, or cached credentials). The error "fatal: Authentication failed" indicates Git received an invalid username/password combination, missing credentials, or misconfigured authentication method. npm does NOT directly handle authentication—it relies on Git's credential system. This means Git credential helpers must be configured, or SSH agent must be running for SSH URLs.

Typical symptoms

  • npm install terminates with 'fatal: Authentication failed'
  • Private Git repository URLs in package.json fail to resolve
  • Build pipelines fail at npm install stage when accessing private repos
  • Works in Git Bash on Windows but fails in PowerShell
  • Successful git clone manually, but npm install fails for same repository

Common causes

  1. SSH keys not configured or SSH agent not running
  2. HTTPS credentials missing or expired personal access token
  3. SSH key has a passphrase but no ssh-agent to unlock it
  4. Wrong SSH key used or SSH config not matching repository host
  5. Credentials not in Git credential store
  6. Two-factor authentication (2FA) enabled but git CLI cannot prompt
  7. Incorrect .npmrc configuration for GitHub Packages

How to fix "npm ERR! git clone git://github.com/user/private-repo.git failed npm ERR! fatal: Authentication failed"

1Verify the repository is accessible manually

Test Git access directly to rule out network or permission issues:

bash
# For SSH access
ssh -T git@github.com

# For HTTPS access
git clone https://github.com/owner/private-repo.git

If SSH test fails with "Permission denied (publickey)", proceed to SSH setup.
If HTTPS test fails with authentication error, configure credentials.

2Set up SSH authentication (for local development)

Generate an SSH key and add it to your Git hosting service:

bash
# Generate SSH key
ssh-keygen -t ed25519 -C "your-email@example.com"

# Start SSH agent and add key
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

# Display public key to copy to GitHub
cat ~/.ssh/id_ed25519.pub

Then:
1. Go to GitHub Settings > SSH and GPG keys
2. Click "New SSH key" and paste the public key
3. Test: ssh -T git@github.com

Update package.json to use SSH URLs:

json
{
  "dependencies": {
    "private-package": "git+ssh://git@github.com:owner/repo.git"
  }
}
3Create and configure a GitHub Personal Access Token (HTTPS)

If using HTTPS authentication, create a token:

1. Go to GitHub Settings > Developer settings > Personal access tokens
2. Generate new token with repo scope
3. Copy the token immediately

Configure in .npmrc:

bash
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PAT

Or embed in package.json URL (less secure):

json
{
  "dependencies": {
    "private-package": "git+https://TOKEN:x-oauth-basic@github.com/owner/repo.git"
  }
}
4Handle CI/CD environment authentication

For GitHub Actions, GitLab CI, or Docker builds:

GitHub Actions:

yaml
- name: Install dependencies
  env:
    GIT_CREDENTIALS_FILE: /tmp/.git-credentials
  run: |
    echo "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com" > $GIT_CREDENTIALS_FILE
    git config --global credential.helper "store --file=$GIT_CREDENTIALS_FILE"
    npm install

Docker (using build secrets):

dockerfile
RUN --mount=type=secret,id=github_token \
    git config --global credential.helper "store" && \
    npm install

Important: Never commit tokens to version control.

5Configure SSH for multiple repositories

If using multiple Git hosts, configure SSH to use different keys:

Create or edit ~/.ssh/config:

bash
Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/github_id_ed25519
  IdentitiesOnly yes

Host gitlab.com
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/gitlab_id_ed25519

Ensure SSH agent has keys loaded:

bash
ssh-add ~/.ssh/github_id_ed25519
ssh-add ~/.ssh/gitlab_id_ed25519
6Handle Two-Factor Authentication (2FA)

If you have 2FA enabled and git cannot prompt interactively:

For HTTPS access, you MUST use a Personal Access Token (regular passwords no longer work):
- Create a PAT with repo scope
- Configure in .npmrc or environment variable
- Do NOT use your GitHub password

For SSH access, 2FA does not apply—SSH keys work normally even with 2FA enabled.

Advanced notes

SSH vs HTTPS Trade-offs:
- SSH: No token/password exposed, works offline, better for development
- HTTPS: Works everywhere HTTP is available, easier in CI/containers

Security Best Practices:
- Never commit credentials to git
- Use read-only tokens with minimal permissions
- Rotate tokens regularly
- For CI systems, use short-lived tokens or service accounts

Debugging:

bash
GIT_SSH_COMMAND="ssh -vvv" npm install

This shows detailed SSH authentication information.

Frequently asked questions

What does "npm ERR! git clone git://github.com/user/private-repo.git failed npm E" mean?
npm fails to install dependencies from private Git repositories when it cannot authenticate with the remote server. json, but the system lacks valid credentials (SSH keys, personal access tokens, or cached credentials). The error "fatal: Authentication failed" indicates Git received an invalid username/password combination, missing credentials, or misconfigured authentication method.
How do I fix "npm ERR! git clone git://github.com/user/private-repo.git failed npm E"?
npm fails to install dependencies from private Git repositories when it cannot authenticate with the remote server. This occurs when the system lacks valid credentials (SSH keys, personal access tokens, or cached credentials) to access the remote repository.
What causes "npm ERR! git clone git://github.com/user/private-repo.git failed npm E"?
SSH keys not configured or SSH agent not running HTTPS credentials missing or expired personal access token SSH key has a passphrase but no ssh-agent to unlock it
Is the "npm ERR! git clone git://github.com/user/private-repo.git failed npm E" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading