32

How does one retrieve an arbritrary user's ssh public keys from GitLab?

GitHub provides this feature. For example: https://github.com/winny-.keys

The GitLab API exposes public keys, however it looks like it requires:

  1. Separate authentication
  2. Query a given user name for its UID
  3. Finally get the public keys
0

2 Answers 2

40

GitHub style ssh public key access was added in GitLab 6.6.0 using the following scheme: http://__HOST__/__USERNAME__.keys (thanks @bastelflp).

Currently we are running 6.2.3, and we will upgrade.

3
  • 4
    From the docu: Retrieving user ssh keys from GitLab publically(github style): http://__HOST__/__USERNAME__.keys
    – bastelflp
    Commented Dec 11, 2015 at 15:21
  • 2
    @bastelflp promote your comment to an answer, and you shall get some votes ;)
    – Arnaud P
    Commented Apr 10, 2018 at 16:45
  • 1
    I'll add it to my answer for the time being.
    – Winny
    Commented Apr 11, 2018 at 20:37
2

You also have, with GitLab 14.9 (March 2022):

New API endpoints for keys and tokens

GitLab 14.9 delivers new REST API endpoints:

  • Return a single SSH key for a specified user. This is useful to enable GitLab SSH keys to be a Terraform-managed resource.
  • Return a single project’s deploy token by ID. This allows for a simple request to return a deploy token instead of returning and sorting through pages deploy tokens with the API.
  • Return a single group access token or project access token.

Thank you Timo Furrer for your contribution!

See Documentation, Issue 354889, Issue 355778 and Issue 355893.

Example:

GET /users/:id/keys/:key_id
{
  "id": 1,
  "title": "Public key",
  "key": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0=",
  "created_at": "2014-08-01T14:47:39.080Z"
}

And See GitLab 15.1 (June 2022) adds:

Deploy keys by user API

Previously, to enable deploy keys for a group of projects, administrator access was required to retrieve the id of the deploy key.

This release adds a new API endpoint (GET /users/:id_or_username/project_deploy_keys) to retrieve all the keys accessible by a given user, so you can complete this task without waiting for an administrator.

In a future iteration, the API will also include public deploy keys.

See Documentation and Issue.

Not the answer you're looking for? Browse other questions tagged or ask your own question.