Skip to main content
  1. Posts/

Resolving the "Could not read from remote repository" Issue

·597 words·3 mins· ·
Xianpeng Shen
Author
Xianpeng Shen
Table of Contents

Recently, while running a Jenkins Job, I encountered this error during a git clone operation:

$ git clone ssh://git@git.companyname.com:7999/repo/opensrc.git
Cloning into 'opensrc'...
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I only encountered this error when I first started using Git, back when I didn’t know how to clone code using SSH. Why did this error appear now? I haven’t changed anything, which is very confusing.

Common Solutions
#

My Google searches didn’t yield a solution for my specific problem. Most results suggested that the issue was due to not having generated an SSH key, and that generating one and adding the public key to GitHub or another web Git management platform would solve the problem. Using GitHub as an example:

First, generate an SSH key:

# Remember to replace with your own email address
ssh-keygen -t rsa -C xianpeng.shen@gmail.com

Second, copy the SSH public key to your Git web platform, such as GitHub.

cd %userprofile%/.ssh
# Open id_rsa.pub and copy its contents
notepad id_rsa.pub

Finally, open https://github.com/settings/ssh/new and paste the copied content there to save it.

This solution was ineffective for my problem, because the same account worked without issue on other virtual machines. Since it was also an HP-UX virtual machine, I generated an SSH key using a different account and the git clone operation worked perfectly. This led me to suspect a difference between the two accounts.

Troubleshooting via SSH Connection Test
#

First, I examined the .gitconfig files for both accounts and found differences. Copying the contents of the .gitconfig file from the working account to the problematic one didn’t resolve the issue.

Second, I noticed that a core file was generated in the current directory during the git clone execution, indicating a coredump. However, opening the core file mostly resulted in gibberish, making it difficult to pinpoint the error.

Finally, I tested the SSH connection using commands. For GitHub, the command is:

ssh -T git@github.com

My problematic clone was using Bitbucket, and its SSH connection test command is:

ssh -vvv git\@bitbucket.org

First, I tested with the account that successfully performed git clone. I’m omitting some of the output here for brevity.

$ ssh -vvv git\@bitbucket.org
OpenSSH_6.2p1+sftpfilecontrol-v1.3-hpn13v12, OpenSSL 0.9.8y 5 Feb 2013      # Different OpenSSH version
HP-UX Secure Shell-A.06.20.006, HP-UX Secure Shell version                  # Different call path
debug1: Reading configuration data /opt/ssh/etc/ssh_config
debug3: RNG is ready, skipping seeding
debug2: ssh_connect: needpriv 0
debug1: Connecting to bitbucket.org [18.205.93.1] port 22.
debug1: Connection established.

... ...

debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).

Then, I tested with the account that failed the git clone operation:

$ ssh -vvv git\@bitbucket.org
OpenSSH_8.0p1, OpenSSL 1.0.2s  28 May 2019                                  # Different OpenSSH version
debug1: Reading configuration data /usr/local/etc/ssh_config                # Different call path
debug2: resolving "bitbucket.org" port 22
debug2: ssh_connect_direct
debug1: Connecting to bitbucket.org [180.205.93.10] port 22.
debug1: Connection established.
Memory fault(coredump)
$

Clearly, different versions of OpenSSH were used, indicating differences in their environment variables. I had previously checked the environment variables, but the large number of variables made it difficult to immediately identify the culprit.

Final Solution
#

I revisited the .profile file for the account where the git clone failed. There was an extra /usr/bin entry in the environment variables, causing this account to use a different version of OpenSSH. HP-UX has very strict requirements on package dependencies and versions. After removing this environment variable, saving the changes, logging back into the virtual machine, and executing git clone, the operation returned to normal.

Related

Git Commit Squash
·226 words·2 mins
How to squash multiple Git commits into a single commit, both locally and remotely, using interactive rebase and merge strategies in Bitbucket.
Jenkins Multibranch Pipeline
·405 words·2 mins
Discusses the use of Jenkins Multibranch Pipeline to manage multiple branches in a project, enabling parallel builds for pull requests and efficient code review processes.
A Code Coverage Tool - Squish Coco use examples
·699 words·4 mins
introduction to Squish Coco, a code coverage tool, with examples of how to set it up and use it in Visual Studio for C++ projects.
Code Coverage tools of C/C++
·168 words·1 min
Code Coverage is a measurement of how many lines, statements, or blocks of your code are tested using your suite of automated tests. It’s an essential metric to understand the quality of your QA efforts.
Jenkins Linux agent configuration
·298 words·2 mins
Provides a step-by-step guide on how to configure a Jenkins Linux agent, including setting up the Java runtime, creating the node, and troubleshooting common issues.
Jenkins Windows agent configuration
·544 words·3 mins
Provides a step-by-step guide on how to configure a Jenkins Windows agent, including setting up the Java runtime, creating the node, and troubleshooting common issues.