多个SSH密钥在同一台设备上 [英] Multiple SSH Keys on the same device

查看:439
本文介绍了多个SSH密钥在同一台设备上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在几个月前注册了个人ssh密钥,并且一切正常。



现在我正在为一家公司工作。他们创建了自己的github帐户,并且我已经创建了一个新的存储库。



我知道我必须添加另一个SSH密钥,我这样做了。



以下是我的〜/ .ssh / config

 主机github .com 
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile〜/ .ssh / id_rsa

Host github-companyname
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile〜/ .ssh / id_rsa_companyname

我也做了 ssh< keyname> ,并且我进行了身份验证。



  git init 
git add
git remote add origin< repo>

并且在此之前它可以正常工作:

  git push -u origin master 

我有这个错误:

 错误:找不到存储库。 
致命:无法从远程存储库读取。

请确保您拥有正确的访问权限
并存在存储库。

我不明白。因为一切似乎都设置正确。



有什么想法?我希望我的解释清楚。我正在运行OSX Sierra 10.12.4



编辑 - 回答



它的工作原理我必须这样更改远程原始URL:

  git remote set-url origin git @ github-< companyname> ;:< githubaccount> /< reponame> .git 

然后我做了以下操作: p>

  git init 
git add。
git commit -m'commit message'
git remote add origin git @ github-companyname:companyname / reponame.git
git push -u origin master

它完美运作!



感谢@IndrekOts帮助我。

解决方案

由于我的评论解决了OP问题,因此我将此作为答案写入。



问题似乎在于,您拥有多个用于同一主机的ssh密钥。在您的 .ssh / config 中,您配置了2个主机 - github.com github-公司名称。在您的公司存储库中,您需要将 .git / config 中的远程URL从 git@github.com:... git @ github-companyname:... 。然后ssh将使用正确的密钥,并且您应该没有身份验证问题。



如需进一步阅读:



当您需要使用您的公司密钥克隆现有存储库时,可以使用相同的方法。

  git clone git @ github-companyname:companyname / repositoryname.git 

请注意,不是 github.com ,该命令使用 github-companyname


I am facing an issue with my github repository.

I registered a personal ssh key months ago and everything worked fine.

Now i'm working for a company. They created their own github account and i have started a new repository.

I know i have to add another SSH key, which i did.

Here is my ~/.ssh/config

Host github.com
    HostName github.com
    User git
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa

Host github-companyname
    HostName github.com
    User git
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_companyname

I also did ssh <keyname> and i am authenticated.

After that i did

git init
git add 
git remote add origin <repo>

and it works fine until then :

git push -u origin master

I've got this error:

ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I don't understand. Because everything seems to be set up correctly.

Any ideas ? I hope my explanations are clear. I am running OSX Sierra 10.12.4

EDIT — answer

To make it works I had to change the remote origin url this way:

git remote set-url origin git@github-<companyname>:<githubaccount>/<reponame>.git

Then I did the following:

git init
git add .
git commit -m 'commit message'
git remote add origin git@github-companyname:companyname/reponame.git
git push -u origin master

And it worked perfectly !

Thanks to @IndrekOts for helping me.

解决方案

Since my comment resolved OPs issue, I'm writing this as an answer.

The problem seems to be in the fact that you have multiple ssh keys for the same host. In your .ssh/config you have configured 2 hosts - github.com and github-companyname. In your company repository, you need to change the remote url in .git/config from git@github.com:... to git@github-companyname:.... Then ssh will use the correct key and you should have no problems with authentication.

For further reading:

When you need to clone an existing repository with your company key, you can apply the same approach.

git clone git@github-companyname:companyname/repositoryname.git

Notice that instead of github.com, the command uses github-companyname.

这篇关于多个SSH密钥在同一台设备上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆