哪个公共SSH密钥用于连接到Git

  • 本文关键字:用于 连接 Git 密钥 SSH git
  • 更新时间 :
  • 英文 :


我已经生成了几个SSH键,并放置在GIT服务器中。执行git clone命令时使用了哪个SSH键?

是否有可能知道使用了哪个SSH键。

您可以通过ssh-add命令看到您的currently active ssh-key

$ ssh-add             # show active ssh-key file path

您也可以自定义。打开~/.ssh/config文件并查找Host <hostname>,然后IdentifyFile指向Git Clone用于该<hostname>id_rsa文件。

$ cat ~/.ssh/config
// sample output
Host bitbucket.org
User git
Hostname bitbucket.org
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

在这里,由于git clone git@bitbucket.org:<user>/<repo>.git使用bitbucket.org主机和用户git,因此~/.ssh/id_rsa文件使用为SSH-KEY,您需要将~/.ssh/id_rsa.pub保存在Bitbucket帐户中。


现在,如果您在〜/.ssh/config文件中添加另一个ssh -key,例如 -

Host bitbucket-alice
User git
Hostname bitbucket.org
PreferredAuthentications publickey
IdentitiesOnly yes
IdentityFile ~/.ssh/alice

您需要使用git clone git@bitbucket-alice:<user>/<repo>.git克隆,它将使用~/.ssh/alice,并且需要在Bitbucket帐户中添加~/.ssh/alice.pub

您可以查看git服务器的身份验证日志文件。在当地的git克隆中,您没有机会。

最新更新