20
22

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.

HerokuでSSH公開鍵(publickey)のpassphraseを求められたら

Posted at

解決策を備忘録として。

#問題
いつものようにHerokuにデプロイしようとしたところ、突然パスフレーズの入力を求められて困惑

$ git push heroku master
Enter passphrase for key '/Users/SomeyaNaoki/.ssh/id_rsa':

#原因
どうやら過去にSSH公開鍵にパスフレーズを設定していたらしいが忘れてしまったみたい

適当に思いつくパスフレーズを入力したが、3回失敗した時点で以下のようなログが

$ git push heroku master
Enter passphrase for key '/Users/SomeyaNaoki/.ssh/id_rsa': #失敗
Enter passphrase for key '/Users/SomeyaNaoki/.ssh/id_rsa': #失敗
Enter passphrase for key '/Users/SomeyaNaoki/.ssh/id_rsa': #失敗
Permission denied (publickey).
fatal: Could not read from remote repository.

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

#解決策
パスフレーズを忘れてしまった場合、既存の公開鍵に新しく設定し直すのは不可能なので、HerokuでSSH公開鍵(public key)を登録する方法(と削除して再登録する方法)を参考に新しくSSH公開鍵を登録し、パスフレーズも再設定します!

1.まずはHerokuにログイン

$ heroku login
Enter your Heroku credentials.
Email: #メールアドレス入力
Password (typing will be hidden): #パスワード入力
Logged in as <メールアドレス>

2.Herokuに登録している鍵を解除

$ heroku keys:clear
Removing all SSH keys... done

3.鍵がなくなったか確認

$ heroku keys
 ▸    You have no SSH keys.

4.新しいSSH公開鍵を登録

$ heroku keys:add
Found an SSH public key at /Users/<username>/.ssh/id_rsa.pub
? Would you like to upload it to Heroku? #Yes
Uploading /Users/SomeyaNaoki/.ssh/id_rsa.pub SSH key... done

5.新しい鍵にパスフレーズを設定

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/<username>/.ssh/id_rsa): #デフォルトで指定された場所が使用されるので何も入力せずにenterでOK
/Users/<username>/.ssh/id_rsa already exists.
Overwrite (y/n)? #y
Enter passphrase (empty for no passphrase): #新しいパスフレーズを入力
Enter same passphrase again: #もう一度入力
Your identification has been saved in /Users/<username>/.ssh/id_rsa.
Your public key has been saved in /Users/<username>/.ssh/id_rsa.pub.
The key fingerprint is:
SHA2~~~~~ランダムな数字~~~~~ <username>@<username>-no-MacBook-Pro.local
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|                 |
|                 |
|    #ランダムな記号図 |
|                 |
|                 |
|                 |
|                 |
+----[SHA256]-----+

6.再度鍵をHerokuに登録

$ heroku keys:add
Found an SSH public key at /Users/<username>/.ssh/id_rsa.pub
? Would you like to upload it to Heroku? #Yes
Uploading /Users/<username>/.ssh/id_rsa.pub SSH key... done

7.完了!これでHerokuに無事pushできました!

$ git push heroku master

8.最後にマイグレーションを忘れずに!

$ heroku run rake db:migrate

#参考にしたサイト
HerokuでSSH公開鍵(public key)を登録する方法(と削除して再登録する方法)
ssh-keygen - 認証用の鍵を生成 - Linuxコマンド

20
22
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
20
22

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?