LoginSignup
8
9

More than 5 years have passed since last update.

GithubにSSH接続できない場合の対処

Posted at

はじめに

今日(2016/07/21)githubからいつものようにレポジトリをpullしたらエラーが発生して接続できない事象が発生。
1週間前まで接続できていたレポジトリで、ローカルもGithubの設定も変更した覚えがなかったが、結論としてはgithubの仕様に沿った設定ができていなかったことが原因だった。
エラーメッセージから判断しにくい問題だったので、同じ問題に遭遇した方の一助になればと思う。

事象

以下のメッセージが出力されGithubのレポジトリにアクセスできない。。。

% git pull origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

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

解消方法

前提条件

Githubアカウント名: shungok
レポジトリ名: Hoge/fuga

手順

■git configの設定確認

% git remote -v
origin   shungok@github.com:Hoge/fuga (fetch)
origin   shungok@github.com:Hoge/fuga (push)

@github.comの左側がGithubアカウント名になっている。
この設定が問題あり。
必ず「git」ユーザを指定する必要がある。

■git configの修正

% git remote set-url origin git@github.com:Hoge/fuga

% git remote -v
origin   git@github.com:Hoge/fuga (fetch)
origin   git@github.com:Hoge/fuga (push)

■pullの確認

% git pull origin master
From github.com:Hoge/fuga
 * branch            master     -> FETCH_HEAD
Already up-to-date.

接続できた。

おわりに

以下のsshが通るものと思い込んでいたが(以前は通っていたような。。。)
gitユーザでなければssh接続できないことが分かった。

% ssh -T shungok@github.com
Permission denied (publickey).

% ssh -T git@github.com
Hi shungok! You've successfully authenticated, but GitHub does not provide shell access.

Githubのトラブルシューティングのページにはっきりとgitユーザしか許容しないと書いてあったが、これまではなぜ接続できていたのか、、、この1週間で仕様が変わったのだろう。

All connections must be made as the "git" user. If you try to connect with your GitHub username, it will fail:

参考URL

8
9
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
8
9