futabooo blog

色々手をつけすぎてすぐに忘れるので備忘録

githubにsshで接続しようとした時にはまった

こちらを参考にしながら進めていました。
ターミナルからgithubのリポジトリにアクセスする設定(sshの設定) - Qiita [キータ]

結論。下記部分はおまけということでやらなかったのが良くなかった。

次はおまけです。sshコマンドのオプションを省略する設定です。

$ vi ~/.ssh/config
Host github.com
 HostName      github.com
 IdentityFile  ~/.ssh/github_id_rsa
 User          git


githubで作成したリポジトリにいざローカルからpushしようとしたらエラー発生

$ git push -u origin master
The authenticity of host 'github.com (192.30.252.129)' can't be established.
RSA key fingerprint is ***************************************
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

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

githubのヘルプをみる
Error: Permission denied (publickey) · GitHub Help

In that example, we did not have any keys for SSH to use. The "-1" at the end of the "identity file" lines means SSH couldn't find a file to use. Later on, the "Trying private key" lines also indicate that no file was found. If a file existed, those lines would be "1" and "Offering public key", respectively:

ヘルプに書いてあったコマンド打ってみる

$ ssh -vT git@github.com
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: Connecting to github.com [192.30.252.128] port 22.
debug1: Connection established.
debug1: identity file /Users/futabooo/.ssh/id_rsa type -1
debug1: identity file /Users/futabooo/.ssh/id_rsa-cert type -1
debug1: identity file /Users/futabooo/.ssh/id_dsa type -1
debug1: identity file /Users/futabooo/.ssh/id_dsa-cert type -1

マイナス1ってことはファイルが見当たらないらしい。。。

今回自分は参考URLみながら「github_id_rsa」って名前で作ったことを思い出した。
そして最初のおまけ設定をすることで解決。

configを書いていないとデフォで「id_rsa」を探しに行くってことなのかな。