Why do I need to run `ssh-add` in my Powershell profile?
Asked Answered
A

1

9

In my Microsoft.PowerShell_profile.ps1 document, I've had to add ssh-add ~/.ssh/github_rsa following the poshgit examples in order for it to connect to my GitHub repos.

# Load posh-git example profile
. 'C:\tools\poshgit\dahlbyk-posh-git-8aecd99\profile.example.ps1'

ssh-add ~/.ssh/github_rsa

If I don't have that in my profile, I Github gives me permissions errors when I try to connect.

If I do it manually, it will work for the entire duration of my desktop session, but as soon as I reboot my computer, I need to re-run the command.

Why doesn't poshgit and ssh-add remember the rsa that I've added? It seems wrong to have to re-add it every time.

Amaze answered 6/9, 2013 at 16:59 Comment(0)
P
24

It's because your rsa key is not the default name ( id_rsa ) so you either need to use ssh-add (which adds it to a running service that remembers the key decrypted with your passphrase) or just add an entry into your ~\.shh\config

~\.ssh\config (create or edit):

Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/github_rsa

Or, if github is the only thing you use ssh keys for, just rename the key to id_rsa and then git (well ssh.exe) will find it for you automatically AND poshgit will ssh-add it for you (to handle passphrases).

Prima answered 6/9, 2013 at 17:34 Comment(6)
ah, that makes perfect sense. It's not my only key since I use two different instances of GitBlit for my business purposes as well.Amaze
Works great. I also renamed github_rsa to id_rsa_github because for some reason, the other way wouldn't work...Amaze
@Chase Florell did you mean rename it to id_rsaChi
@tofutim, no... doing that would make it the default.Amaze
my posh-git doesn't seem to read the config file - did you do something different than the default?Chi
Another line one could add is "Preferredauthentications publickey" making sure the key is really used.Paleobotany

© 2022 - 2024 — McMap. All rights reserved.