我的~/.ssh
包含两个密钥对:
id_rsa_foo
&安培; id_rsa_foo.pub
foousername
的github.com
)id_rsa_bar
&安培; id_rsa_bar.pub
barusername
的github.com
)barusername
(indefero.myserver.com
) ~/.ssh/config
“知道”关键文件:
#github.com-foousername account
Host github.com-foousername
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_foo
#github.com-barusername account
Host github.com-barusername
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_bar
#indefero.myserver.com-foousername account
Host indefero.myserver.com-foousername
HostName indefero.myserver.com
User foousername
IdentityFile ~/.ssh/id_rsa_bar
~/.ssh/known_hosts
“知道”服务器:
github.com,207.97.227.239 ssh-rsa AAAAB3N...AaQ==
204.232.175.90 ssh-rsa AAAAB3N...AaQ==
indefero.myserver.com,111.222.333.444 ssh-rsa AAAAB3N...Ytw==
现在,当我尝试从GitHub克隆时,出现错误:Permission denied (publickey). fatal: The remote end hung up unexpectedly
user@machine ~/Desktop/test
$ git clone git@github.com:foousername/project1.git
Cloning into 'foousername'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
但是,当我首先在本地计算机上创建存储库并设置本地/项目config
时:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com-foousername:foousername/project1.git
我可以pull
/ push
。 (这种方式适用于GitHub repos,myserver ropos甚至不需要密码:indefero@indefero.it-and-t.com's password:
。但可能是另一个问题。)
如何更改此行为,以便克隆回购?
答案 0 :(得分:1)
您已正确设置~/.ssh/config
,但未在git clone
命令中使用正确的主机。使用您在配置文件中设置的主机名来使用相应的密钥:
# Use your default key
git clone git@github.com:foousername/project1.git
# Use the ~/.ssh/id_rsa_foo key
git clone git@github.com-foousername:foousername/project1.git
# Use the ~/.ssh/id_rsa_bar key
git clone git@github.com-barusername:barusername/project1.git