LoginSignup
5
4

More than 5 years have passed since last update.

Windows Server 2016にGit for Windowsをインストールし、複数人開発でバージョン管理システムを作成するとき、sshは通るのにgit cloneがエラーになるときの対処法

Last updated at Posted at 2019-04-08

はじめに

会社内でGitを利用した開発ソースコードのバージョン管理システムを構築するにあたり、Windows ServerにGit For Windowsをインストールして複数人開発でのバージョン管理システムを作成するとき、参考サイトのように設定しながら構築作業を進めていたところ、次のようなエラーに悩まされたのでその時の対処法をメモする。

発生したエラー

Windows ServerでOpenSSHのsshdを起動し、開発用PCからssh接続によりgit cloneしたとき、下記のようなエラーが発生しクローン出来なかった。

[ユーザー名]@[コンピューター名] MINGW64 ~
$ git clone ssh://[ユーザー名]@[サーバーのIPアドレス]/c:/repos/test.git
Cloning into 'test.git'...
[ユーザー名]@[サーバーのIPアドレス]'s password:


fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Windows ServerでGit For Windowsのsshdを起動したときは上記エラーは発生せずcloneができる。しかしながら接続するユーザー名でsshdを起動しないと下記のような別のエラーが発生したので対処法を考えなけらばならなくなった。

Windows Serverの方でadministratorにて/usr/bin/sshd.exeを起動し、クライアントからadministrator以外の接続ユーザー名でssh接続したときWindows Server側で発生するエラーは下記のようなものであった。

debug1: temporarily_use_uid: 1049696/1049089 (e=1049076/1049089)
seteuid 1049696: Operation not permitted
debug1: do_cleanup
debug1: Killing privsep child 7364

構築するバージョン管理システムのイメージ

ソース管理環境構築イメージ.jpg

インストールしたソフト

Window Server 2016

  • Git for Windows (2.21.0) 64-bit version
  • Win32-OpenSSH v7.9.0.0p1-Beta

開発作業用PC

  • Git for Windows (2.21.0) 64-bit version

バージョン管理システム作成時に参考にしたサイト

対処方法

参考にしたサイトのように設定するとエラーが発生して思うように動作しなかったので、次のような手順を追加した。

  1. Window Server上のGit For Windowsの各コマンドが保存されているフォルダにパスを通す。
  2. Window Server上のユーザーにリモートリポジトリへのアクセス権(読み/書き)を追加する。
  3. Window Server上のOpenSSHのデフォルトシェルをGit for Windowsのbashへ変更する。

1. Window Server上のGit For Windowsの各コマンドが保存されているフォルダにパスを通す。

コントロールパネルのシステムの詳細設定を開き、「環境変数」を開く。

次のような環境変数を追加する。

・ C:\Program Files\Git\cmd
・ C:\Program Files\Git\usr\bin
・ C:\Program Files\Git\bin
・ C:\Program Files\Git\mingw64\bin
・ C:\Program Files\Git\mingw64\libexec\git-core

2. Window Server上のユーザーにリモートリポジトリへのアクセス権(読み/書き)を追加する。

Active Directoryにて開発者用のグループやポリシーを作成している場合は、開発者グループの書き込み権限をGitのリポジトリのフォルダに付与する。

3. Window Server上のOpenSSHのデフォルトシェルをGit for Windowsのbashへ変更する。

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Program Files\Git\git-bash.exe" -PropertyType String -Force 

確認

OpenSSHのsshdを起動する。

  1. 2. 3. を設定したのち、net start sshdによりOpenSSHのsshdを起動する。 ※念のためPsExec64にて、system権限で起動する。

git clone

作業用PCからssh接続にてgit cloneすると下記のように成功する。

[ユーザー名]@[コンピューター名] MINGW64 ~/source
$ git clone ssh://[ユーザー名]@[サーバーのIPアドレス]/c/repos/test.git
Cloning into 'test'...
[ユーザー名]@[サーバーのIPアドレス]'s password:
warning: You appear to have cloned an empty repository.
5
4
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
5
4