我已经生成了几个SSH键,并放置在GIT服务器中。执行git clone
命令时使用了哪个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克隆中,您没有机会。