简体   繁体   中英

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.

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. 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 .

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.

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.

My guess is the loaded SSH key isn't used when doing a pull/push/fetch via PowerShell, but that's only a guess.

Is there something else I need to configure in PowerShell to use my loaded SSH key to do something in 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 . 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 . After this certificate is used, I'm successfully connected to 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. I've named my private key jan (or in the question above 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).

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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