15. February 2017

GitHub unable to clone repository – Permission denied (publickey)

After upgrade to new version of SSH you may experience the following problem with return code 255:

Permission denied (public key).
fatal: Could not read from remote repository.

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

This happened to me after upgrade from Linux Mint 17 to 18.

How to diagnose the problem?

Run following command:

ssh -v git@github.com

You will see several lines of output and one of them is typically the reason. In my case it was:

...
debug1: SSH2_MSG_NEWKEYS received
debug1: Skipping ssh-dss key ~/.ssh/id_dsa - not in PubkeyAcceptedKeyTypes
...

DSA keys were disabled in SSH 7. Solution is to generate new key with different type, for example RSA.

ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub

Replace your key at GitHub by newly generated one. You can re-run “ssh -v” command to check whether the communication was established correctly:

PTY allocation request failed on channel 0
Hi georgik! You've successfully authenticated, but GitHub does not provide shell access.
...
debug1: Exit status 1

That’s a good sign. The connection was established and now you can try to clone a repo.

1. June 2013

GitLab: Could not read from remote repository

When you try to push to GitLab you may end up with following error message:

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

It’s not very clear what’s real cause. You may check the permission, but it might not solve the problem.

One quick solution could be just restart of GitLab service. It still might not help.

Let’s learn some mechanics of GitLab.

You send data via ssh to GitLab server. When authentication by key is succesfull then server will invoke gitlab-shell. This will shell send request to web interface of GitLab. Yes, web interface. Then it will allow you to access git repository.

Schema:

git -> ssh -> sshd -> gitlab-shell -> gitlab web

The problem described in the beginning of this article is between gitlab-shell and gitlab-web. Most likely shell is not able to access gitlab web. URL is broken or host configuration is incorrect or port is not reachable.

Just go to gitlab-shell project and open file config.yml. You’ll see something like this:

gitlab_url: "http://localhost:80/"

Test this URL directly on server e.g. by links:

links http://localhost:80/

You may need to change hostname or port or add base directory to URL. Fix the URL so the gitlab-shell is able to access web interface. Restart gitlab service and try to push again.

Further discussion about this and similar problems is available at github.

1. December 2012

Common mistake when creating new git repo. Error: src refspec master does not match any.

Creating new git repo and pushing it to remote server is fairly easy.

mkdir my-project
cd my-project
git init

You can work with project localy. When you want to push it to remote server, then it is necessary to add remote repo url.

git remote add origin <MY-URL>

Now you can push it:

git push -u origin master

When it works. Hooray. Sometimes you may find following error:

error: src refspec master does not match any.
error: failed to push some refs to '<MY-URL>'

The reason why this happens is not that obvious. :-)

Git creates master branch only after commit to your local repo. If you just initialize repo then there is no master. How to fix it?

Just add and commit at least one change to your repo and re-run push command. You can add e.g. .gitignore.

You can find more info at StackOverflow.

26. January 2011

IntelliJ Idea – Windows – Git – The remote end hung up

I was trying to clone git repository. I had brand new Windows with Cygwin version of git. Intellij Idea displayed nice helpful error message:

fatal: The remote end hung up unexpectedly

I found article at grublesmurf.org that pointed me to solution.

Problem was that Cygwin was using directory c:\cygwin\home\georgik\.ssh, but Intellij Idea was trying to read c:\Users\georgik\.ssh. I moved .ssh directory to c:\Users\georgik and set HOME variable to %USERPROFILE%.It is also worthy to modify /etc/passwd in cygwin to match that directory.