简体   繁体   English

哪个公共ssh密钥用于连接git

[英]Which public ssh key was used to connect to git

I have generated several ssh keys and have placed in git server. 我已经生成了几个ssh密钥,并将其放置在git服务器中。 Is it possible somehow to know which ssh key was used while executing git clone command? 是否有可能以某种方式知道执行git clone命令时使用了哪个ssh密钥?

You can see your currently active ssh-key by ssh-add command. 您可以通过ssh-add命令查看currently active ssh-key

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

You can customize it also. 您也可以自定义它。 Open ~/.ssh/config file and find Host <hostname> , then the IdentifyFile points the id_rsa file that git clone is using for that <hostname> . 打开~/.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

Here, As git clone git@bitbucket.org:<user>/<repo>.git is using bitbucket.org Host and user git , so ~/.ssh/id_rsa file is using as ssh-key and you need to save ~/.ssh/id_rsa.pub in BitBucket account. 在这里,由于git clone git@bitbucket.org:<user>/<repo>.git使用bitbucket.org Host和用户git ,因此~/.ssh/id_rsa文件用作ssh-key,您需要保存~/.ssh/id_rsa.pub在BitBucket帐户中。


Now, if you add another ssh-key in ~/.ssh/config file like - 现在,如果您在〜/ .ssh / config文件中添加另一个ssh-key,例如-

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

You need to clone with git clone git@bitbucket-alice:<user>/<repo>.git and it will use ~/.ssh/alice and you need to add ~/.ssh/alice.pub in your BitBucket account. 您需要使用git clone git@bitbucket-alice:<user>/<repo>.git进行克隆,它将使用~/.ssh/alice并且需要在您的BitBucket帐户中添加~/.ssh/alice.pub

You can look into the authentication log file of your Git server. 您可以查看Git服务器的身份验证日志文件。 In the local Git clone you have no chance. 在本地Git克隆中,您没有机会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM