What is the public URL for the Github public keys

GitGithubBitbucketPublic Key

Git Problem Overview


I heard that there was a public URL for all users on github where you can access their public keys or they can supply that URL of all their public keys. Is this true? If so what is that URL. Does it exist for bitbucket as well?

Git Solutions


Solution 1 - Git

You can get with:

curl https://github.com/<username>.keys

Replace <username> with the actual username of the GitHub user.

This is useful when you set login permission to other servers. Just save its output into ~/.ssh/authorized_keys. To append it to the end from the command line:

curl https://github.com/<username>.keys | tee -a ~/.ssh/authorized_keys

It can also be done using Github API

curl -i https://api.github.com/users/<username>/keys

For bit bucket you can use the following: (This call requires authentication.)

curl -i https://bitbucket.org/api/1.0/users/<accountname>/ssh-keys

Solution 2 - Git

GPG public keys are now available at https://github.com/<username>.gpg

Solution 3 - Git

Works for gitlab same way too.

https://gitlab.com/<username>.keys

Works nicely in bash scripts too.

#GitProvider to fetch public keys (gitlab.com,github.com)
GitProvider="gitlab.com"
GitUsername="username"
curl https://${GitProvider}/${GitUsername}.keys | tee -a ~/.ssh/authorized_keys

Solution 4 - Git

In addition these also provide a way to retrieve a user's PGP keys:

GitHub:

https://github.com/USER.keys
https://gitlab.com/USER.gpg

GitLab:

https://gitlab.com/USER.keys
https://gitlab.com/USER.gpg

Solution 5 - Git

While the keys are public you don't always want to reveal your internal hostnames from the default comment fields, so I'd recommend ssh-copy-id command if you have SSH password access, wormhole when on console and configuration management tools (like Ansible, Puppet etc) in the first place.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfrazrasView Question on Stackoverflow
Solution 1 - GitfrazrasView Answer on Stackoverflow
Solution 2 - GitBrian DView Answer on Stackoverflow
Solution 3 - GitMik RView Answer on Stackoverflow
Solution 4 - GitItay GrudevView Answer on Stackoverflow
Solution 5 - GitkravietzView Answer on Stackoverflow