Problem when adding SSH key on github


Recently, I had I problem with github. I couldn't add SSH keys anymore, the web page would just hang and present me a "Connection reset" error after a few (annoying) minutes. I struggled for a week, but have finally found a solution, which is not the best, but at least I can access github from my machine once again.

It all started two weeks ago, when I ran an everyday git push, and got a little surprise. It just sat there forever, and I had to SIGTERM it every time. What I did after was try to reset my key on github. I went to the SSH page and deleted my key, created a new one and tried to add it.

Yes I know it was stupid. The right way to do it would be:

  1. back up my key
  2. create a new one
  3. add it
  4. make absolutely sure it works
  5. remove the old one in github and on the machine

But I didn't, for one simple reason: adding keys has been such a natural operation, I didn't even think about it. Replacing a key (which I did a lot of times when I was learning how public-key encryption works) only takes a few seconds, and I never had to worry about it. Until now.


I am no ssh expert. So I turned to github's support. And I have to say, the response was really good, fast and to the point. Sadly, it didn't solve the problem. Here is the response:

Hi Bruno,

What size SSH key are you using? We have a known bug where the page will give a 500 error if the SSH key is too large.

I would recommend using the default size key for now, and hopefully we will have this bug fixed soon.

Sorry for the trouble.


It turns out the problem wasn't the key size, but you can see Steve gave a really polite response. Anyway, I started trying everything to make it work, but in a week I just couldn't do it. Then, yesterday, I decided to give the developer API a try. I didn't have much hope that it would work, because I had tried a lot of different things and because I thought the problem was exactly there. But I was wrong again.

With just a few commands, I was able to add a ssh key to my account and finally access my repositories. And, in the process, I discovered a handy command line utility, so I guess it wasn't all that bad.

curl (a.k.a. cURL)

curl is a program you can use to fetch web pages just as your browser would do. It is present on most distributions, so you can start right away and run

$ curl

And you'll get the HTML output of the page. You can use that to access the github API. To list all the keys of an account, you'd use

$ curl -u bbguimaraes

Use the -u option to set the username. You will be prompted for the password. The switch accepts the form -u user:password, but that just isn't very nice. You will get back a json output, listing all the keys registered for your account. There are several functions on the API, you can take a look at them on the docs page.

But the one that did it for me was the create a puclib key. A simple post

$ curl \
    -u bbguimaraes \
    -d '{"title": "[...]", "key": "ssh-rsa AAA[...]"}' \

and, after a week of awful manual syncing of code, I was finally able to use my beloved github repositories as I always had. I hope this text can save you some time if you ever happen to have the same problem.

curl git github