Search code examples
gitlabssh-keys

GitLab: How to find the owner of an SSH key


Given an SSH public key or fingerprint that has been registered with GitLab, how do I find out which account is associated with that key?

Note that the key may have been registered as a "deploy key," in which case I'd like to know account that registered it.

I'd prefer to know ways to do this using both the standard web UI (if possible), and programatically via the REST API. If neither of these are possible, I'll take answers that involve digging into the internals of GitLab (e.g., via a query on GitLab's database) if necessary.


Solution

  • In GitLab 12.6 the Keys API introduced a method to get a user by SSH key fingerprint.

    curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/keys?fingerprint=01:23:45:67:89:ab:cd:ef:01:23:45:67:89:ab:cd:ef"
    

    If the key happens to be a deploy key, in GitLab 12.7 the same keys endpoint was enhanced to get a user by deploy key fingerprint as well.

    Note that both of these methods are only available to GitLab adminstrators.