LoginSignup
4
4

More than 5 years have passed since last update.

SSHでgit clone したときにエラー

Posted at

前座

開発環境を Ubuntu 16.04 から Windows 10 WSL 上で動作する Ubuntu 18.04 に切り替えたところ、 git clone でエラーをはくようになってしまった。ggってもよくわからないし、結構長時間ハマったので、メモ。

環境

前述のとおり、以下が動作環境

Ubuntu 18.04 / WSL

エラー内容

以下のようなエラーが出る。

$ git clone ssh://git@git.myserver.com:10022/MyGroup/awesome-project.git
Cloning into 'awesome-project '...
git@git.myserver.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

ssh の設定がうまくいってないことはわかる‥

ssh 設定内容

~/.ssh/config には以下のように設定している。
gitlabを立てており、IdentityFileで設定した鍵で接続する設定だ。
内部でポートフォワードしているため、ポートが一般的でないかもしれないが、その他は極めて普通に設定だ。

Host myhost
  HostName git.myserver.com
  IdentityFile ~/.ssh/id_rsa
  User git
  Port 10022

解決策

以下でいけた。

$ git clone myhost:/MyGroup/awesome-project.git

違うのはホスト名のところ。configで設定したエイリアスをURLに指定している。

要するにconfigで設定したHost名で接続しないと設定をみてくれないみたいだ。

今までの環境だと普通にフルパス名で接続できたし、ggってもこのような例はあまり出てこなかった。もしかしたらgitのバージョンの動作差分なのかもしれないが、そこまでは調査できていない。

4
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
4
4