170
165

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.

[GitHub] 公開鍵登録の際に、Permission denied (publickey). が出続ける場合の対応 (vagrantからsshする場合の注意も)

Last updated at Posted at 2014-04-30

手順通りにやっていけば基本は大丈夫。
https://help.github.com/articles/generating-ssh-keys

まずは: 鍵作成

$ cd ~/.ssh
$ ssh-keygen -t rsa -C "your_email@example.com"
Generating public/private rsa key pair.
# Enter file in which to save the key (/Users/you/.ssh/id_rsa): github_id_rsa(ここは任意)
Enter passphrase (empty for no passphrase): (ここも任意)
# Enter same passphrase again: (ここも任意)
$ ssh-add ~/.ssh/id_rsa

ssh-add がうまくいかない

こんなエラーが出ることもあります。

Could not open a connection to your authentication agent.

そんな時はおまじない。

eval `ssh-agent`

これをうった後に ssh-add hogehoge をすると通ります。

次に: GitHubに公開鍵を登録

公開鍵の中身をコピー

# macなら
$ pbcopy < ~/.ssh/id_rsa.pub

GitHubのサイトの上部ナビゲーションバーの設定アイコンから、アカウント設定を選択 > SSH鍵設定 にアクセス

Screen Shot 2014-04-30 at 18.09.53.png

まるっと貼り付け

Screen Shot 2014-04-30 at 18.10.04.png

ミスった点

GitHubのリポジトリの中に、Setting > Deploy Key という部分があり、そこから登録するのは違います。
注意。。。

Screen Shot 2014-04-30 at 18.11.20.png

Screen Shot 2014-04-30 at 18.11.35.png

最後に: 接続

接続テスト

ssh -T git@github.com

エラーが出たら

~/.ssh/knownhostsの整理
⇒github.comで始まる行を削除

多分これでなんとかなるはず。

Gitでcommit

$ git init
$ git add .
$ git commit -m "hoge"

鍵の場所を指定

$ vim ~/.ssh/config
---
Host github
    HostName github.com
    User git
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/github_id_rsa(それぞれの環境に合わせて)
---
$ git push -u origin master
170
165
3

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
170
165

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?