【Rails】git push時に、Permission denied (publickey)エラー
嵌ったのでメモ。
■OS
Windows
現象
「git push heroku master」で以下のエラー。
$ git push heroku master Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
対処方法
1. ~/.ssh/config を作成
以下の内容を書いて、configファイルを作成
Host github.com User git port 22 Hostname github.com IdentityFile ~/.ssh/github_rsa TCPKeepAlive yes IdentitiesOnly yes Host heroku.com User git port 22 Hostname heroku.com IdentityFile ~/.ssh/heroku_id_rsa TCPKeepAlive yes IdentitiesOnly yes
2.公開鍵の作成
この記事を参考に公開鍵を作成
名前は「heroku_id_rsa」で作成(上のconfigファイルと整合性を取ること)
$ ssh-keygen -C (Herokuに登録したメールアドレス) -t rsa
3.公開鍵の登録
先ほどの「heroku_id_rsa」を登録
$ heroku keys:add Found the following SSH public keys: 1) github_rsa.pub 2) heroku_id_rsa.pub Which would you like to use with your Heroku account? 2 Uploading SSH public key C:/Users/HOGEHOGE/.ssh/heroku_id_rsa.pub... done
4.成功!
$ git push heroku master Counting objects: 240, done. ・・・
■参考サイト
configファイルに設定するところ
http://opamp.hatenablog.jp/entry/20110914/1316011399
configファイルとは
http://nauthiz.hatenablog.com/entry/20100919/1284892108