我已按照tutorial为多个github帐户设置SSH密钥。
但我一直收到错误
ssh: Could not resolve hostname github-psdtowordpresspro.com: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
遵循的步骤:
id_rsa_psdtowordpresspro.pub
目录中创建了SSH密钥:.ssh
文件。 (请注意,此文件夹之前不存在。所以我必须创建一个)使用语法ssh-keygen -t rsa -C "your-email-address"
将SSH密钥添加到我的第二个github帐户
添加了密钥
ssh-add~ / .ssh / id_rsa_COMPANY
使用命令
创建.config
文件
触摸〜/ .ssh / config vim config
这是我在.config
文件中编写的代码
Host github-regipheirim
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_psdtowordpresspro
这正是教程中提到的。
然后我将远程原点添加为
git remote add origin git@github-psdtowordpresspro.com:regipheirim/regi.git
但是当我尝试推送它时,显示错误“#34;主机名无法解析。"
以下是
的屏幕截图Git remote connection setting of second account
项目.config
文件
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = git@github-regipheirim:regipheirim/regi.git
fetch = +refs/heads/*:refs/remotes/origin/*
[user]
name = regipheirim
email = p.regidev@gmail.com
还试过(根据TJL在评论部分提出的建议)
git remote set-url origin git@github.com:regipheirim/regi.git
但是当我试图用
推进时git push origin master
我再次收到错误:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
所以任何人都可以帮助我解决我在这里做错的事情。我只花了整个星期天搞清楚。
答案 0 :(得分:1)
您没有链接到您在配置文件中创建的别名
尝试:
git remote add origin git@github-regipheirim:regipheirim/regi.git
答案 1 :(得分:0)
来自同一服务的多个帐户的解决方案。在这种情况下,对于Bitbucket。
~/.gitconfig
文件例如,对于用户JohnDoe
(在~/.ssh/id_rsa_john_1
中使用rsa键),您应该添加
Host bitbucket.org:JohnDoe
User JohnDoe
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa_john_1
IdentitiesOnly yes
您要尝试通过SSH克隆的URL中也应存在该用户名,例如:
git clone git@bitbucket.org:JohnDoe/my_project.git
当您在同一服务中拥有不同的帐户时,您也可以添加它:
Host bitbucket.org:RichardRoe
User RichardRoe
HostName bitbucket.org
IdentityFile ~/.ssh/id_rsa_richard_1
IdentitiesOnly yes
因此,在文件中,您将有两个有关bitbucket.org
的部分。
感谢您可以使用单独的帐户(具有不同的RSA密钥)。
eval $(ssh-agent)
ssh-add
因此,此示例为:
ssh-add -K ~/.ssh/id_rsa_john_1
和
ssh-add -K ~/.ssh/id_rsa_richard_1