Github 公钥的公共 URL 是什么

我听说在 github 上有一个面向所有用户的公共 URL,您可以访问他们的公共密钥,或者他们可以提供所有公共密钥的 URL。这是真的吗?如果是这样,那么这个 URL 是什么。它也是为 Bitbucket 而存在的吗?

48764 次浏览

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

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

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

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.

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