[英]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.