GitHubのソースコードをSourceTreeでcloneしようとしたらエラーが出た話

何をしたか

GitHub用の秘密鍵を別PCに持ってきてSourceTreeでcloneしようとしたら、リポジトリが認識されなかった。

 

こういう感じのエラーが出る

The server's host key is not cached. You have no guarantee that the server is the computer you think it is.

 

If you trust this host, enter "y" to add the key to PuTTY's cache and carry on connecting. If you want to carry on connecting just once, without adding the key to the cache, enter "n". If you do not trust this host, press Return to abandon the connection. Store key in cache? (y/n, Return cancels connection, i for more info) fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

SSHでknown_hostsに記録を残すように、PuTTYも同様のしくみを持っているそうで。

当然SourceTreeでyを押せるわけではないので、そこでエラーになるらしい。

 

解決法

初めてGitHub秘密鍵を使って接続する場合は、SourceTree内蔵PuTTYplink.exeを使ってyを押すと解決する。

plinkの正確な場所は、スタートメニューなどからSourceTreeを右クリックして「ファイルの場所を開く」で開いて、ショートカットのプロパティを開いた時の「作業フォルダー」から探した方がよい

"作業フォルダーのパス\tools\putty\plink.exe" -ssh -C -i "秘密鍵のパス" git@github.com

ここでyを押して、GitHubからHi!って挨拶されればOK。

もう一度SourceTreeを操作すれば、リポジトリタイプがGitとして認識されるはず。

 

参考:

サーバが移転した場合は下記が参考になりそう。