LoginSignup
6
3

More than 3 years have passed since last update.

Windows10を Git サーバとするとき、git clone ssh:// 時リポジトリが見つからない

Last updated at Posted at 2019-08-27

TL;DR

サーバ側 Windows の ssh ログインシェルを Git bash に変更し、フルパスの前に /mntを付けて clone する。

URLの具体例
git clone ssh://hidao@192.168.0.254/mnt/c/users/hidao/repo/app.git

検証環境

サーバOS: Windows10 Pro 64bit ver. 1903
Git: 2.18.0.windows.1
sshd: OpenSSH_7.7p1, OpenSSL 1.0.2o 27 Mar 2018(アプリと機能のオプション機能で追加したもの)

クライアントOS: Windows10 Home 64bit ver. 1903
Git: 2.19.0.windows.1
ssh: OpenSSH_7.7p1, OpenSSL 1.0.2p 14 Aug 2018(アプリと機能のオプション機能で追加したもの)

特殊な事情

Windows10 のアプリと機能からインストールできる sshd では、デフォルトシェルが cmd.exe です。

ただし、cmd では git clone ssh:// 時に UNIX 形式のパス指定ではリポジトリに到達できないため(原因不明)、ログインシェルを Git bash に変更する回避策を取ります。

また、Git bash はドライブを /mnt の下にマウントしているため、リモートから URL を指定する場合に /mnt の追加が必要になります。

ハマりポイント

  1. ssh のログインシェルがデフォルトの cmd.exe では、一般的な URL 表記法ではリポジトリに到達できない。
  2. ssh のログインシェルを Git bash に変更すると、Git bash をローカルで使っているときと異なり、フルパスの先頭に /mnt を追加する必要がある。

付録:ssh のログインシェルを Git bash に変更する PowerShell コマンド

下記コマンドを実行し、bash のパスを調べます。

入力
Get-Command bash | Format-Table -AutoSize -Wrap
出力
CommandType Name     Version        Source
----------- ----     -------        ------
Application bash.exe 10.0.18362.239 C:\WINDOWS\system32\bash.exe

次に、出力で得られた Source のパスを含むコマンドを管理者権限で下記要領にて実行します。

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\WINDOWS\system32\bash.exe" -PropertyType String -Force

以下のような出力が得られれば、ログインシェルの変更に成功しています。

DefaultShell : C:\WINDOWS\system32\bash.exe
PSPath       : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\OpenSSH
PSParentPath : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE
PSChildName  : OpenSSH
PSDrive      : HKLM
PSProvider   : Microsoft.PowerShell.Core\Registry
6
3
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
6
3