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

4.6k Views Asked by At

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.

1

There are 1 best solutions below

6
On BEST ANSWER

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