[英]Which public ssh key was used to connect to git
我已经生成了几个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
Host和用户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克隆中,您没有机会。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.