Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gitlab

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
like image 402
Winny Avatar asked Jul 19 '14 10:07

Winny


People also ask

Where are GitLab SSH keys stored?

By default, all GitLab SSH keys must go in an . ssh folder under the user's home directory.

How do I get my SSH public key from GitHub?

Add your public key to GitHubLogin to github.com and bring up your account settings by clicking the tools icon. Select SSH Keys from the side menu, then click the Add SSH key button. Name your key something whatever you like, and paste the contents of your clipboard into the Key text box. Finally, hit Add key to save.


2 Answers

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.

like image 94
Winny Avatar answered Oct 17 '22 06:10

Winny


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"
}
like image 24
VonC Avatar answered Oct 17 '22 06:10

VonC