LoginSignup
4
6

More than 5 years have passed since last update.

Git Bash で Permission denied (publickey) が毎回出る場合の原因と対策

Posted at

環境

  • Windows 10
  • Git 2.8.1

現象

Git Bash を起動するたびにssh-add keyを実行しないと、Remoteにアクセスするコマンド(git pullなど)を実行できない。
キーを登録しないと、以下のように怒られる。

Permission denied (publickey).
fatal: Could not read from remote repository.

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

原因

  • 登録している ssh キーの名称がデフォルト(id_rsa)ではない1

対策

/etc/ssh/ssh_config
にキーを指定してやる

設定手順

  1. 普通にGit Bashを立ち上げる
  2. タスクバー上のアイコンをCtrl-Shift-Clickする(管理者権限でGit Bashが立ち上がる)2
  3. vim /etc/ssh/ssh_config
  4. 以下を追記する
Host bitbucket.org
    HostName bitbucket.org
    User git
    Port 22
    IdentityFile ~/.ssh/my_rsa

これは、↓と等価とのこと1
ssh git@bitbucket.org -p 22 -i ~/.ssh/my_rsa


  1. 問題の原因および対策 [メンチカツには醤油でしょ!!

  2. Git Bashを管理者権限で実行する方法 [@YamasakiKenta

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