0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ssh -T git@github.comが通るのにgit fetchできないとき

0
Posted at

問題

以下のように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
省略...
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?