我的~/.ssh
包含两个密钥对:
id_rsa_foo
&id_rsa_foo.pub
foousername
对于GitHub 上的用户(github.com
)
id_rsa_bar
&id_rsa_bar.pub
barusername
对于GitHub 上的用户(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 存储库,myserver ropos 甚至不需要密码:indefero@indefero.it-and-t.com's password:
。但可能是另一个问题。)
为了克隆 repos,我该如何改变这种行为?