How to fix npm ERR! git clone git://github.com/user/private-repo.git failed npm ERR! fatal: Authentication failed in npm
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- Verify the repository is accessible manually
- Set up SSH authentication (for local development)
- Create and configure a GitHub Personal Access Token (HTTPS)
- Handle CI/CD environment authentication
# For SSH accessssh -T git@github.com# For HTTPS accessgit clone https://github.com/owner/private-repo.gitnpm ERR! git clone git://github.com/user/private-repo.git failednpm 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
- 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
- Wrong SSH key used or SSH config not matching repository host
- Credentials not in Git credential store
- Two-factor authentication (2FA) enabled but git CLI cannot prompt
- 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"
Test Git access directly to rule out network or permission issues:
# For SSH access
ssh -T git@github.com
# For HTTPS access
git clone https://github.com/owner/private-repo.gitIf SSH test fails with "Permission denied (publickey)", proceed to SSH setup.
If HTTPS test fails with authentication error, configure credentials.
Generate an SSH key and add it to your Git hosting service:
# 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.pubThen:
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:
{
"dependencies": {
"private-package": "git+ssh://git@github.com:owner/repo.git"
}
}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:
//npm.pkg.github.com/:_authToken=YOUR_GITHUB_PATOr embed in package.json URL (less secure):
{
"dependencies": {
"private-package": "git+https://TOKEN:x-oauth-basic@github.com/owner/repo.git"
}
}For GitHub Actions, GitLab CI, or Docker builds:
GitHub Actions:
- 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 installDocker (using build secrets):
RUN --mount=type=secret,id=github_token \
git config --global credential.helper "store" && \
npm installImportant: Never commit tokens to version control.
If using multiple Git hosts, configure SSH to use different keys:
Create or edit ~/.ssh/config:
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_ed25519Ensure SSH agent has keys loaded:
ssh-add ~/.ssh/github_id_ed25519
ssh-add ~/.ssh/gitlab_id_ed25519If 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:
GIT_SSH_COMMAND="ssh -vvv" npm installThis 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
- 📚npm Official Documentation
- 💬Stack Overflow: npm authentication error(Stack Overflow)
- 🐙
- 💬CircleCI: Private npm package authentication(Stack Overflow)