39
31

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.

"Permission denied (publickey)"と表示されたときの対処法

Last updated at Posted at 2016-09-19
$ git pull origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

と表示されたときの対処法。

私の場合、このエラーが出る直前に、
次のようなコマンドを実行した覚えがありました。

$ ssh-keygen

おそらく、同名のkeyを生成してしまったため、今までのkeyが上書きされてしまったのだと思います。

このエラーに対して、私が講じた解決策は、

SSHの鍵を作成し直し、Githubに登録し直すこと

です。

以下、手順です。

$ cd ~/.ssh
$ ssh-keygen -t rsa -C address@example.com

// address@example.com は自分のメールアドレス

$ chmod 600 id_rsa

以下を' ~/.ssh/config 'へ追加します。

~/.ssh/config
Host github
  HostName github.com
  IdentityFile ~/.ssh/id_rsa
  User git

MacOSの方は、

$ pbcopy < ~/.ssh/id_rsa.pub

WindowsOS(WSL)の方は、

$ chmod 600 ~/.ssh/config
$ alias clip='clip.exe'
$ clip < ~/.ssh/id_rsa.pub

Githubの右上のリストから、Settingsを選び、
飛んだページでSSH & GPG keysを選択、
さらにNew SSH keyで出てきたフォームにペーストしてください。
//Titleは適当で構いません

最後にTerminalに戻って、

$ ssh -T git@github.com

以上です。

当記事が、どなたかの一助となれば幸いです。

※ 追記 ( 2018/06/26 )

Mac以外の環境では下記のコマンドが必須のようです。

$ ssh-add
39
31
6

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
39
31

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?