How to fix fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. in Git

GitBEGINNERMEDIUMUpdated Dec 6, 2025· 374 views

This error occurs when Git cannot establish a connection to the remote repository. Common causes include SSH key issues, incorrect repository URLs, missing access permissions, or network problems preventing the connection.

Quick fix

Fixes fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

ssh -T git@github.com
  1. Verify your SSH connection to the remote host
  2. Check if your SSH key exists and is loaded
  3. Generate a new SSH key if needed
  4. Add your SSH key to your Git hosting account
git — error
ssh -T git@github.com
fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

What this error means

The "fatal: Could not read from remote repository" error indicates that Git attempted to communicate with a remote repository (like one hosted on GitHub, GitLab, or Bitbucket) but failed to establish a connection. This is a generic error that can stem from several different underlying issues. The error message "Please make sure you have the correct access rights and the repository exists" provides two main hints: 1. **Access rights**: Your authentication method (SSH keys or HTTPS credentials) may not be configured correctly, or you may not have permission to access the repository 2. **Repository exists**: The remote URL might be incorrect, the repository may have been deleted or renamed, or it might be a private repository you cannot access This error commonly appears when: - Cloning a repository for the first time - Pushing or pulling changes - Fetching updates from upstream - Working with submodules that reference remote repositories

Typical symptoms

  • Git push, pull, clone, or fetch commands fail with 'fatal: Could not read from remote repository'
  • SSH operations to the remote host fail with 'Permission denied (publickey)'
  • Error appears after changing computers or generating new SSH keys
  • Error occurs in CI/CD pipelines when accessing private repositories
  • Submodule updates fail with repository access errors
  • Error appears after repository was renamed, moved, or made private

Common causes

  1. SSH key not added to your GitHub/GitLab/Bitbucket account
  2. SSH agent not running or key not loaded into the agent
  3. Incorrect remote URL (typo in repository name or organization)
  4. Repository is private and you don't have access
  5. Repository has been deleted, renamed, or moved
  6. SSH key permissions are incorrect (too open)
  7. Wrong SSH key being used (multiple keys, wrong identity)
  8. Firewall or proxy blocking SSH connections (port 22)
  9. GitHub/GitLab host not in known_hosts file
  10. Using HTTPS URL but Git is configured for SSH (or vice versa)

How to fix "fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists."

1Verify your SSH connection to the remote host

First, test if you can connect to the remote Git server via SSH:

For GitHub:

bash
ssh -T git@github.com

For GitLab:

bash
ssh -T git@gitlab.com

For Bitbucket:

bash
ssh -T git@bitbucket.org

Expected success message (GitHub):

bash
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

If you see "Permission denied (publickey)", your SSH key is not configured correctly. If you see a connection timeout, there may be network/firewall issues.

2Check if your SSH key exists and is loaded

Verify that you have an SSH key and it's loaded into the SSH agent:

Check for existing SSH keys:

bash
ls -la ~/.ssh

Look for files like id_ed25519, id_rsa, id_ecdsa (private keys) and their .pub counterparts.

Start the SSH agent and add your key:

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

# Add your key (replace with your key name)
ssh-add ~/.ssh/id_ed25519
# or
ssh-add ~/.ssh/id_rsa

Verify the key is loaded:

bash
ssh-add -l

If no keys are loaded, you'll see "The agent has no identities."

3Generate a new SSH key if needed

If you don't have an SSH key, generate one:

bash
# Generate a new ED25519 key (recommended)
ssh-keygen -t ed25519 -C "your_email@example.com"

# Or generate an RSA key (for older systems)
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

When prompted:
- Press Enter to accept the default file location
- Enter a passphrase (recommended) or press Enter for no passphrase

Add the key to your SSH agent:

bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

Copy the public key to your clipboard:

bash
# macOS
cat ~/.ssh/id_ed25519.pub | pbcopy

# Linux (with xclip)
cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard

# Windows (Git Bash)
cat ~/.ssh/id_ed25519.pub | clip
4Add your SSH key to your Git hosting account

Add the public key to your GitHub/GitLab/Bitbucket account:

GitHub:
1. Go to Settings > SSH and GPG keys > New SSH key
2. Give it a descriptive title
3. Paste your public key
4. Click "Add SSH key"

GitLab:
1. Go to Preferences > SSH Keys
2. Paste your public key
3. Set an expiration date (optional)
4. Click "Add key"

Bitbucket:
1. Go to Personal settings > SSH keys
2. Click "Add key"
3. Paste your public key
4. Click "Add key"

Verify it works:

bash
ssh -T git@github.com
5Check and fix the remote URL

Verify your remote URL is correct:

bash
git remote -v

Example output:

bash
origin  git@github.com:username/repo.git (fetch)
origin  git@github.com:username/repo.git (push)

Common issues to check:
- Typo in username or repository name
- Repository was renamed or moved to a different organization
- Using SSH URL (git@github.com:) but SSH isn't set up
- Using HTTPS URL (https://) but need to use SSH

Update the remote URL if needed:

bash
# Change to SSH
git remote set-url origin git@github.com:username/repo.git

# Change to HTTPS
git remote set-url origin https://github.com/username/repo.git

Verify the repository exists by visiting it in your browser.

6Check SSH key file permissions

SSH requires strict permissions on key files. Fix permissions if they're too open:

bash
# Set correct permissions on .ssh directory
chmod 700 ~/.ssh

# Set correct permissions on private key
chmod 600 ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_rsa

# Set correct permissions on public key
chmod 644 ~/.ssh/id_ed25519.pub
chmod 644 ~/.ssh/id_rsa.pub

# Set correct permissions on config file
chmod 600 ~/.ssh/config

If permissions are too open, SSH will refuse to use the key and you'll see warnings like:

bash
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
7Configure SSH to use the correct key

If you have multiple SSH keys, configure SSH to use the right one for each host:

Create or edit ~/.ssh/config:

bash
nano ~/.ssh/config

Add configuration for your Git host:

bash
# GitHub
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github
    IdentitiesOnly yes

# GitLab
Host gitlab.com
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/id_ed25519_gitlab
    IdentitiesOnly yes

# Work GitHub (using different key)
Host github-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_work
    IdentitiesOnly yes

For the work alias, update your remote:

bash
git remote set-url origin git@github-work:company/repo.git
8Use SSH over HTTPS port if port 22 is blocked

Some networks block SSH port 22. Use port 443 instead:

Test if port 443 works:

bash
ssh -T -p 443 git@ssh.github.com

Configure SSH to always use port 443 for GitHub:

Edit ~/.ssh/config:

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

Or use HTTPS with credential caching:

bash
# Switch to HTTPS
git remote set-url origin https://github.com/username/repo.git

# Cache credentials for 1 hour
git config --global credential.helper 'cache --timeout=3600'

# Or store credentials permanently (less secure)
git config --global credential.helper store
9Debug SSH connection issues

Use verbose mode to diagnose SSH connection problems:

bash
# Verbose SSH connection test
ssh -vT git@github.com

Key things to look for in the output:

1. "Offering public key" - Shows which key SSH is trying to use
2. "Server accepts key" - Key was accepted
3. "Permission denied" - Authentication failed
4. "Connection timed out" - Network/firewall issue

Common debug patterns:

bash
# Key not found
debug1: No more authentication methods to try.
Permission denied (publickey).

# Wrong key being offered
debug1: Offering public key: /home/user/.ssh/id_rsa
debug1: Authentications that can continue: publickey

# Key file permissions issue
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
10Add host to known_hosts if prompted

If this is your first time connecting to a host, SSH will ask you to verify its authenticity:

bash
The authenticity of host 'github.com (140.82.121.4)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

Verify the fingerprint against the official documentation:
- GitHub: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/githubs-ssh-key-fingerprints
- GitLab: https://docs.gitlab.com/ee/user/gitlab_com/#ssh-host-keys-fingerprints

If it matches, type `yes` to add to known_hosts.

In CI/CD environments, you may need to pre-populate known_hosts:

bash
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts

Advanced notes

Deploy Keys vs User SSH Keys:

For CI/CD pipelines accessing private repositories, consider using deploy keys:
- Deploy keys are repository-specific SSH keys
- They provide read-only access by default (can be set to read-write)
- Safer than using personal SSH keys in CI/CD

Generate and add a deploy key:

bash
# Generate a key specifically for the repository
ssh-keygen -t ed25519 -f ~/.ssh/deploy_myrepo -C "deploy-key-myrepo"

Then add the public key as a deploy key in your repository settings.

Personal Access Tokens (PAT) for HTTPS:

If SSH doesn't work in your environment, use a Personal Access Token with HTTPS:

bash
git clone https://oauth2:YOUR_TOKEN@github.com/username/repo.git

# Or configure credential helper to store the token
git config --global credential.helper store
git clone https://github.com/username/repo.git
# Enter your username and PAT when prompted

GitHub CLI Alternative:

The GitHub CLI (gh) can handle authentication automatically:

bash
# Install and authenticate
gh auth login

# Clone repositories
gh repo clone username/repo

Submodule Issues:

If the error occurs with submodules:

bash
# Update submodule URLs to match your access method
git config --file=.gitmodules submodule.mysubmodule.url git@github.com:org/submodule.git
git submodule sync
git submodule update --init --recursive

SSH Agent Forwarding:

When working on remote servers and needing access to private repos:

bash
# Connect with agent forwarding
ssh -A user@server

# On the server, verify your key is available
ssh-add -l

Windows-Specific Issues:

On Windows, ensure you're using the Git Bash SSH, not Windows OpenSSH:

bash
# Check which SSH Git is using
git config --global core.sshCommand

# Force Git to use Git Bash SSH
git config --global core.sshCommand "C:/Program Files/Git/usr/bin/ssh.exe"

Frequently asked questions

What does "fatal: Could not read from remote repository. Please make sure you hav" mean?
The "fatal: Could not read from remote repository" error indicates that Git attempted to communicate with a remote repository (like one hosted on GitHub, GitLab, or Bitbucket) but failed to establish a connection. This is a generic error that can stem from several different underlying issues. The error message "Please make sure you have the correct access rights and the repository exists" provides two main hints: 1.
How do I fix "fatal: Could not read from remote repository. Please make sure you hav"?
This error occurs when Git cannot establish a connection to the remote repository. Common causes include SSH key issues, incorrect repository URLs, missing access permissions, or network problems preventing the connection.
What causes "fatal: Could not read from remote repository. Please make sure you hav"?
SSH key not added to your GitHub/GitLab/Bitbucket account SSH agent not running or key not loaded into the agent Incorrect remote URL (typo in repository name or organization)
Is the "fatal: Could not read from remote repository. Please make sure you hav" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading