問題
以下のようにgithub.comへ疎通できるが、gitコマンド実行時に権限エラーが発生していた。
PS> ssh -T git@github.com
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
PS> git fetch
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.
原因
gitコマンドが内部で使用しているsshが実際に疎通に使用しているsshと異なっていた。
Git for WindowsではLinux標準コマンドはGit Bashに含まれており、 以下のssh.exe`が使用される
C:\Program Files\Git\usr\bin\ssh.exe
そのため、Windows標準の以下のssh.exeで疎通できてもgitコマンドが失敗するという事象が発生していた。
PS> Get-Command ssh
CommandType Name Version Source
----------- ---- ------- ------
Application ssh.exe 9.5.5.1 C:\WINDOWS\System32\OpenSSH\ssh.exe
gitのssh.exeをWindows標準のものを使うようにする
PS> git config --global core.sshCommand "C:/WINDOWS/System32/OpenSSH/ssh.exe"
Get-Commandで取得したパスをそのまま指定するのではなく、バックスラッシュをスラッシュに置き換える必要がある
PS> git config --global --list
省略...
core.sshcommand=C:/WINDOWS/System32/OpenSSH/ssh.exe
省略...