I have generated several ssh keys and have placed in git server. Is it possible somehow to know which ssh key was used while executing git clone
command?
You can see your currently active ssh-key
by ssh-add
command.
$ 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>
.
$ 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.
Now, if you add another ssh-key in ~/.ssh/config file like -
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.
You can look into the authentication log file of your Git server. In the local Git clone you have no chance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.