17

I couldn't find a way to get my or other people's public key from Github, but the Ubuntu Server installer can.

How can it and how could I get an ssh public key via GitHub username in a script myself?

0

4 Answers 4

30
curl -O https://github.com/<username>.keys 
curl -O https://gitlab.com/<username>.keys

will retrieve the public keys uploaded for the given username. Both github and gitlab work.

4
  • 1
    Is this documented somewhere? Dec 31, 2019 at 11:30
  • @ThorbjørnRavnAndersen sorry I found it in my personal documents with a reference to a U+L link but not documentation.
    – Rinzwind
    Dec 31, 2019 at 17:02
  • Indeed. github.com and gitlab.com don't store the secret key, so it's impossible to retrieve that one.
    – pts
    Dec 31, 2019 at 17:54
  • Very useful, but how can I tell them apart? I have multiple SSH keys on my account. Sep 17, 2021 at 0:14
8

In this particular instance ssh-import-id retrieves an SSH key from GitHub for you. The tool can import from both GitHub and Launchpad. Normally the tool takes the retrieved key and adds it to your authorized keys file which is what Ubuntu Server would have been doing. The manual page outlines the mechanics of the specific API calls it makes to retrieve the key.

2
  • Is there ssh-import-id for Red Hat based systems as well? I couldn't find it in the default repositories for CentOS (epel) & Fedora. Jan 1, 2020 at 15:44
  • 1
    @u15p7fgy863eiq5 The utility was written by Dustin Kirkland so it is a solution born in the Ubuntu world. To use it in the Red Hat-based world you could secure it via PyPi: pypi.org/project/ssh-import-id. Jan 1, 2020 at 16:08
3

In addition to Rinzwind's answer, Github has an API for this.

The API is not the URL described by Rinzwind, but it appears to be in addition to that.

1
1

The exact usage is ssh-import-id gh:github_username

See the manpages

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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