久々にherokuにpushしようとしたら詰まった
heroku create後にpushすると以下のエラー。
$ 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.
結果
結論から言うとこのエラーを解決するために、以下3つチェックする羽目になりました。
1. heroku keys
2. ssh確認
3. heroku accounts
1.
keyが無効になってるのかと思い
$ heroku keys
で確かめるとしっかり登録されている。
念の為秘密鍵を再度追加
$ heroku keys:add ~/.ssh/id_rsa.pub
残念ながら、これでは解決しませんでした。ま、heroku keysで登録済みでしたからね。
2.
https://devcenter.heroku.com/articles/keys
この辺りに書いてあるのですが、まずsshで接続出来るかを確認しました。
~/.ssh/configに設定を書いていたのでそれを利用
$ ssh -v heroku ... debug1: Authentication succeeded (publickey). ... Authenticated to heroku.com ([50.19.85.156]:22). ...
問題なし。これでもgit push heroku master出来ず。
3.
原因は明確には分からないがこれで解決。
複数herokuアカウントを扱うためにheroku accountsを利用していました。
https://github.com/ddollar/heroku-accounts
$ heroku accounts * user1 user2
この状態でuser1で問題なくheroku app作成は出来てました。
$ heroku accounts:set user2 $ heroku accounts:set user1
アカウントを一度切り替えると, git push heroku masterが成功しました。
考察
heroku accountsの挙動を理解しておらず、詰まった。
https://github.com/ddollar/heroku-accounts/blob/master/lib/accounts/heroku/command/accounts.rb
ソースを見てみると、heroku accountsはgit remote先を変更することで対応している。
heroku create時に設定されるremote先はgit@heroku.com:repo.gitのような形式のため正常にpush出来なかった。
(heroku.com用の設定を消して、heroku.user1, heroku.user2のみ設定を行っていたため)
気付いてしまえば、なんということはなかった\(^o^)/
そもそも、2の時点で気付けなかったおれ\(^o^)/
結論
heroku accounts利用者は
heroku create
後に
heroku accounts:set username
でおけ。