问题背景
我们经常会对不同服务器生成不同密钥使用,github不允许不同机器使用同一个密钥,所以需要生成不同密钥,但是每次使用git的时候,默认查找~/.ssh/rsa
密钥文件,有时候我们的GitHub并不是使用的这个密钥文件,这时候就需要指定密钥文件使用git
解决办法
假设我们使用的密钥文件为~/.ssh/rsa_github
。
clone
时命令:git clone git@github.com:用户名/仓库名.git --config core.sshCommand="ssh -i 指定密钥文件路径(~/.ssh/rsa_github)"
- 或者已经下载的git仓库,在仓库的
./.git/config
文件中[core]
部分添加sshcommand = ssh -i 指定密钥文件路径(~/.ssh/rsa_github)