簡體   English   中英

哪個公共ssh密鑰用於連接git

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM