这可能是一种非常不寻常的情况,但我想指定在本地计算机上执行shell(git)命令时要使用的私有SSH密钥。
基本上是这样的:
git clone git@github.com:TheUser/TheProject.git -key "/home/christoffer/ssh_keys/theuser"
或者更好(用Ruby):
with_key("/home/christoffer/ssh_keys/theuser") do
sh("git clone git@github.com:TheUser/TheProject.git")
end
我见过使用Net::SSH连接到远程服务器的示例,该服务器使用指定的私钥,但这是一个本地命令。有可能吗?
如果这里的其他解决方案都不适合您,并且您已经创建了多个ssh密钥,但仍然无法执行以下简单操作
git pull
那么假设您有两个ssh密钥文件
id_rsa
id_rsa_other_key
然后在git repo中,尝试:
# Run these commands INSIDE your git directory
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa_other_key
并通过以下方式确保github默认用户名和userid正确:
# Run these commands INSIDE your git directory
git config user.name "Mona Lisa"
git config user.email "mona.lisa@email.com"
看见https://gist.github.com/jexchan/2351996了解更多信息。
最快、最简单的方法是:
使用ssh克隆您的repo:
git-c core.sshCommand=“ssh-i~/.ssh/<your_key>”克隆git@github.com:<user>/<repo>.git
然后cd到克隆的repo中,然后:
git-config-core.shCommand'ssh-i~/.ssh/<your_key>'
要测试它是否工作:
git--git-dir=/path/to/repo/.git pull
所以你可能会想:为什么我在github中安装了.pub,而private在默认目录中之后,我创建的ssh密钥就不起作用了?
该文档为我们提供了一个澄清问题的命令:ssh-vTgit@github.com
输出显示了git查找的ssh密钥列表。因此,您可能希望使用这些名称之一创建密钥,或者使用上述过程来包含所需的密钥。