简体   繁体   English

在PowerShell中添加ssh-add以添加我的Git密钥,接收权限被拒绝

[英]Did ssh-add in PowerShell to add my Git key, receiving permission denied

I'm in the process of tuning my development console a bit. 我正在调整我的开发控制台。 At the moment I'm trying to mod my PowerShell experience a bit and want to use it as my primary console. 目前我正在尝试修改我的PowerShell体验,并希望将其用作我的主控制台。

This is working out quite nicely and I'm now busy implementing my Git key to the console, so I can push, pull, etc. via PowerShell. 这很好用,我现在正忙着在控制台上实现我的Git键,所以我可以通过PowerShell推送,拉动等。 What I've done so far is installing Git for Windows and while installing the Git Extensions I made sure I've added the Linux commands to my path by selecting the option Use Git and optional Unix tools from the Windows Command Prompt . 到目前为止我所做的是安装Git for Windows,在安装Git Extensions时,我确保通过Use Git and optional Unix tools from the Windows Command Prompt选择Use Git and optional Unix tools from the Windows Command Prompt Linux命令添加到我的路径中。

Afterward, I've run the following commands. 之后,我运行以下命令。

# Check status of service
Get-Service ssh-agent

# Check the start type of the service
Get-Service ssh-agent | Select StartType

# Set the start type to manual
Get-Service -Name ssh-agent | Set-Service -StartupType Manual

# Start the service
Start-Service ssh-agent

# Adding my certificate
ssh-add $env:USERPROFILE\.ssh\myCertificate

When doing a push (or a pull/fetch for that matter), I'm receiving a Permission denied message. 在进行推送(或拉取/获取)时,我收到一条Permission denied消息。

PS> git push origin master
Warning: Permanently added the RSA host key for IP address '140.82.118.4' to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

I'm receiving this message on multiple systems. 我在多个系统上收到此消息。 The exact same key does work in the installed Git Bash console, so this should not be the problem. 完全相同的密钥在安装的Git Bash控制台中起作用,因此这不应该是问题。

My guess is the loaded SSH key isn't used when doing a pull/push/fetch via PowerShell, but that's only a guess. 我的猜测是在通过PowerShell进行拉/推/提取时没有使用加载的SSH密钥,但这只是猜测。

Is there something else I need to configure in PowerShell to use my loaded SSH key to do something in Git? 我需要在PowerShell中配置其他东西以使用我加载的SSH密钥在Git中执行某些操作吗?

Update 更新

I've figured out an work-around, but this is suboptimal . 我已经找到了解决办法,但这不是最理想的

What I've also tried is the following command ssh -vT git@github.com . 我也尝试过以下命令ssh -vT git@github.com When running this command I see a lot happening and in the end this is trying to connect to GitHub via my certificate C:\\\\Users\\\\jan/.ssh/myCertificate . 运行此命令时,我看到很多事情发生,最后这是尝试通过我的证书C:\\\\Users\\\\jan/.ssh/myCertificate连接到GitHub。 After this certificate is used, I'm successfully connected to GitHub. 使用此证书后,我已成功连接到GitHub。 So if this certificate is used, I can actually do stuff. 因此,如果使用此证书,我实际上可以做的事情。

Well, I figured it out (partly). 好吧,我想(部分)。

Git, by default, searches for a key called id_rsa , which isn't present on my system. 默认情况下,Git会搜索名为id_rsa的密钥,该密钥在我的系统中不存在。 I've named my private key jan (or in the question above myCertificate . 我已经将我的私钥命名为jan (或者在myCertificate上面的问题中。

Even though I've loaded this certificate via ssh-add , it isn't used when trying to do a pull , push , etc. After renaming my file to id_rsa I am able to do these actions (if I specify my passphrase again). 即使我已经通过ssh-add加载了这个证书,但在尝试执行pullpush等时不会使用它。将文件重命名为id_rsa我可以执行这些操作(如果我再次指定我的密码) 。

While this works, I don't want to use this renamed file. 虽然这有效,但我不想使用这个重命名的文件。 In order to use a different private key for GitHub, I've created the following file ~\\.ssh\\config with the following contents. 为了给GitHub使用不同的私钥,我创建了以下文件~\\.ssh\\config其中包含以下内容。

host github.com
 HostName github.com
 IdentityFile ~/.ssh/jan
 User git

While this works, it is a suboptimal solution in my opinion. 虽然这有效,但在我看来这是一个次优的解决方案。 Also because I have to specify my passphrase again when doing something with my remote(s). 另外,因为在使用遥控器做某事时我必须再次指定我的密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM