1
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?

More than 5 years have passed since last update.

cmderでgithubを利用している際のPermission denied (publickey)対策

Last updated at Posted at 2019-10-19

Windowsのコマンドプロンプトをかっこよく使うためのコンソールソフトcmderでgitを使っていると、ふとした拍子に次のエラーが表示されてgithubに接続できなくなることがあります。

$ git pull
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.

解決策

次の箇所で指定可能なsshの設定を見直すと良いです。

  1. C:\Program Files\Git\etc\ssh\ssh_config
  2. C:\Program Files (x86)\Git\etc\ssh\ssh_config
  3. C:\<cmderのインストール先>\cmder\vendor\git-for-windows\etc\ssh\ssh_config
  4. C:\Users\<ユーザ名>\.ssh\config

解説

cmderに限らずWindowsでgitを利用する際は(WSLは別として)何らかのgitクライアントをインストールしますが、接続先の鍵情報などはsshの設定ファイルに記述します。

1や2のファイルはgit for windows用のssh設定として多くのサイトで紹介されていますが、cmderはFULLを指定してインストールすると独自のgit for windowsを別途インストールするので設定ファイルの場所が変わり、3のファイルとなります。ここまでは結構検索に引っ掛かるのですが、最近オリジナルのgit for windowsを再インストールした際に冒頭のエラーが出るようになり、調べると4のファイルへ設定が必要になっていました。

設定内容(参考まで)

参考までに、ssh_configや.ssh/configへ追記するgithubへの最低限の接続設定は次の通りです。

Host github.com
    HostName github.com
    User git
    IdentityFile C:/<鍵ファイルの格納フォルダ>/<github用の秘密鍵>
1
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
1
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?