Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Powershell中使用SSH密钥推送到两个不同的GitHub帐户?_Git_Github - Fatal编程技术网

如何在Powershell中使用SSH密钥推送到两个不同的GitHub帐户?

如何在Powershell中使用SSH密钥推送到两个不同的GitHub帐户?,git,github,Git,Github,我在Windows 10上,安装了Git for Windows。我将代码推送到两个不同的GitHub帐户,并尝试设置我的SSH代理使用两个密钥(每个帐户一个密钥) 这是我的~\.ssh\config: Host github.com-userone HostName github.com User git IdentityFile ~/.ssh/id_rsa Host github.com-usertwo HostName github.com Use

我在Windows 10上,安装了Git for Windows。我将代码推送到两个不同的GitHub帐户,并尝试设置我的SSH代理使用两个密钥(每个帐户一个密钥)

这是我的
~\.ssh\config

Host github.com-userone
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa

Host github.com-usertwo
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_usertwo
如果我使用GitBash推/拉,它可以正常工作,但我也希望能够使用Powershell。当我尝试从Powershell执行推送或拉送操作时,会出现“请确保您具有正确的访问权限”错误。如果我从Powershell运行
start ssh agent.cmd
,那么
git push
适用于该Powershell实例

如果我将
start ssh-agent.cmd
添加到我的
profile.ps1
profile中,那么ssh-agent将启动并且
git-push
正常工作,但这似乎破坏了我的Powershell配置文件的其他方面(如下所示)。
导入模块
设置主题
不再工作。我没有得到任何错误;我只是不再得到我的时髦git或者我的git造型

Import-Module oh-my-posh
Import-Module posh-git
Set-Theme Paradox
Set-Location "c:\users\brubin\documents\visual studio 2017\projects"
start-ssh-agent.cmd
我找到的大多数使其工作的指令都涉及运行
eval$(ssh-agent-s)
,但是
eval
在Powershell中不起作用


如何设置它,以便使用Powershell从两个不同的GitHub帐户推/拉?

首先,只有在创建私钥时使用密码短语保护私钥时,才需要ssh代理

其次,确保使用正确的SSH URL表单,引用那些~/.SSH/config条目:

github.com-usertwo:<usertwo>/myRepo
Cd到您的
$home\.ssh dir
并执行
ssh add.\
将您的私钥文件(和密码短语)添加到ssh代理。
最后一步是让Git for Windows使用Windows本机
ssh.exe

为此,请执行:
git config--global core.sshCommand C:/WINDOWS/System32/OpenSSH/ssh.exe

就这样!现在ssh代理正在运行并为您的密码短语提供服务。重新启动后,它将继续执行此操作(无需重新输入您的密码)。
甚至更好的是,ssh代理将适用于从“开始”菜单而不是PowerShell控制台启动的应用程序(如Visual Studio)——您必须使用
start ssh-agent.cmd
来执行此操作

注:

我在
开始菜单中键入了“
服务
”,得到了一个窗口,列出了机器上当前安装的所有服务。
我注意到,在“
OpenSSH身份验证代理
”旁边,它说“
停止了

我运行了
Get Service ssh-agent | Set Service-StartupType-Manual-PassThru
,然后
Start Service ssh-agent
,它工作了。
好像服务被禁用了或者什么的。我从来没有在Windows上接触过这些东西,也许它在默认情况下是“停止”的


谢谢你,我按照你的说明完成了它,并为第二个用户的存储库设置了远程URL,比如
git remote set URL origingit@github.com-usertwo:usertwo/repo_name.git
一个问题-现在我得到了
警告:代理返回了不同的签名类型ssh rsa(预期为rsa-sha-512)
。在GitHub上似乎有关于它的讨论,但我对SSH的理解还不够清楚,不清楚他们在说什么。这有什么好担心的吗?你说的是本鲁宾吗?您可以使用ssh-keygen-t ecdsa-b 521-P创建一个新密钥,而不是使用
ssh-keygen-t ecdsa-b 521-P
。。。(因为当前与Windows打包的ssh代理还不接受典型的rsa密钥)是的,就是这个。这个错误是否意味着我的ssh代理没有验证远程服务器的身份?@BenRubin我想是的,因为这是一个警告。使用ssh-Tv github.com usertwo测试它
Get-Service ssh-agent | Set-Service -StartupType Automatic -PassThru | Start-Service