PowerShell / Win32-OpenSSH

Win32 port of OpenSSH
7.39k stars 758 forks source link

Custom keyfile names not supported/working #1995

Open aurorapar opened 1 year ago

aurorapar commented 1 year ago

Prerequisites

Steps to reproduce

Only keyfile's with the name "id_rsa" and "id_rsa.pub" work with ssh-agent. Create a new SSH key with a custom name or change an existing key's name. Add SSH key with custom name to ssh-agent.

Expected behavior

Adding an ssh keyfile with any name allows authentication for various services.

Actual behavior

Authentication is not permitted when using an ssh keyfile with a name other than "id_rsa" and "id_rsa.pub"

Error details

No response

Environment data

PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN> dir C:\Users\Nulrie\.ssh

    Directory: C:\Users\Nulrie\.ssh

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        10/27/2022   3:45 PM           2636 known_hosts
-a----         10/3/2022   8:02 PM           1221 known_hosts.old
-a----         10/3/2022   9:30 AM           2655 notalabs
-a----         10/3/2022   9:30 AM            576 notalabs.pub

PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN> git pull
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.
PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN> ssh-add C:\Users\Nulrie\.ssh\notalabs
Enter passphrase for C:\Users\Nulrie\.ssh\notalabs:
Identity added: C:\Users\Nulrie\.ssh\notalabs (Nulrie@DESKTOP-HNI86N4)
PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN> git pull
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.
PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN>

PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN> dir C:\Users\Nulrie\.ssh

    Directory: C:\Users\Nulrie\.ssh

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        10/27/2022   3:45 PM           2636 known_hosts
-a----         10/3/2022   8:02 PM           1221 known_hosts.old
-a----         10/3/2022   9:30 AM           2655 notalabs
-a----         10/3/2022   9:30 AM            576 notalabs.pub

PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN> git pull
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.
PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN> ssh-add C:\Users\Nulrie\.ssh\notalabs
Enter passphrase for C:\Users\Nulrie\.ssh\notalabs:
Identity added: C:\Users\Nulrie\.ssh\notalabs (Nulrie@DESKTOP-HNI86N4)
PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN> git pull
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.
PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN> dir C:\Users\Nulrie\.ssh

    Directory: C:\Users\Nulrie\.ssh

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         10/3/2022   9:30 AM           2655 id_rsa
-a----         10/3/2022   9:30 AM            576 id_rsa.pub
-a----        10/27/2022   3:45 PM           2636 known_hosts
-a----         10/3/2022   8:02 PM           1221 known_hosts.old

PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN> ssh-add C:\Users\Nulrie\.ssh\id_rsa
Enter passphrase for C:\Users\Nulrie\.ssh\id_rsa:
Identity added: C:\Users\Nulrie\.ssh\id_rsa (Nulrie@DESKTOP-HNI86N4)
PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN> git pull
Enter passphrase for key '/c/Users/Nulrie/.ssh/id_rsa':
Already up to date.
PS C:\Users\Nulrie\Documents\Work\NOTA\code\Pre-Alpha_NOGEN>

Version

5.1.19041.1320

Visuals

No response

tgauth commented 1 year ago

I think this may be Git specific - you could confirm by testing a regular ssh connection with a custom keyfile name.

Can you take a look at https://www.howtogeek.com/devops/how-to-use-a-different-private-ssh-key-for-git-shell-commands/#:~:text=Simply%20run%20ssh-keygen%20and%20specify%20a%20new%20key,with%20the.pub%20extension.%20ssh-keygen%20-t%20rsa%20-f%20~%2F.ssh%2Fgithub?

It suggests using ~/.ssh/config or a manual override with GIT_SSH_COMMAND to point to the custom keyfile.