2

First off all, I'm starting to get really desperate on this one (been working on this for about an week, without any luck). The forums of Gitlab didn't answer at all, so I hope that you guys will bear this one with me.

I've problems adding an SSH key to my gitlab server trough the API (It works well trough the webpage).

Gitlab information: Gitlab Information

I came across this issue (which was fixed here) which was related to an "wrong" openssh implementation. They've fixed this in milestone 7.10. Only thing... My server has openssh 6.6 installed:

OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3, OpenSSL 1.0.1f 6 Jan 2014

Now, I don't know if that fix is backwards compatible or not, but maybe good to mention.

Also, the logs show no warning or errors or whatsoever. The /tmp/gitlab_key* files are generated on the server: output of /tmp/gitlab_key*

The problem I'm facing is that gitlab can't create the fingerprint trough the API. This is the responce I get from the API:

{
    "message": {
        "fingerprint": ["cannot be generated"]
    }
}

So right now I have no idea what the problem could be. I've been struggling with this for almost a week now, so I really hope that his problem could be fixed.

-just for the record, here's the script I'm using to add the ssh-key trough the API

Mathlight
  • 5,847
  • 15
  • 58
  • 103

3 Answers3

5

id_rsa.pub is base64 encoded file, it contains + character

http post with application/x-www-form-urlencoded, need encode it's content preventing + being convert to (space)

try

curl --data-urlencode "key=$key_pub" --data-urlencode "title=$hostname" \
http://gitlabserver/api/v3/user/keys?private_token=$Token

see: this

papanito
  • 1,387
  • 2
  • 16
  • 33
linarnan
  • 102
  • 1
  • 6
4

Improving on @Mathlight's answer the following snippet uploads public ssh key to gitlab.com

curl -X POST -F "private_token=${GITLAB_TOKEN}" -F "title=$(hostname)" -F "key=$(cat ~/.ssh/id_rsa.pub)" "https://gitlab.com/api/v3/user/keys"
Sandeep
  • 24,819
  • 3
  • 27
  • 23
2

OP here

In the mean time I've updated the server to version 8.8 and changed the curl code a bit and now it's working like a charm:

curl -X POST -F "private_token=${userToken}" -F "title=${sshName}" -F "key=${sshKey}" "${gitServer}/user/keys"

Just in case anybody needs this in the future...

Mathlight
  • 5,847
  • 15
  • 58
  • 103