SSH public key login problem

何が起こったか全くわからないが、自分向けのメモ。

これまで、

~/.ssh/config

Host github
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_github
  User git

~/Documents/freebsdPostInstall/.git/config

...
[remote "origin"]
        url = git@github.com:username/freebsdPostInstall.git
...

のように記入していて問題なく利用できていた。はず。にも関わらず、最近これではpushできなくなった。

% cd ~/Documents/freebsdPostInstall/
% git push 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.

~/.ssh/configのHost行が間違っており、この場合は、

% ssh -T git@github

としてloginできる。しかし、.git/configではgit@github.comでloginしようとしてだめと言われる。

なので、
~/.ssh/config

Host github.com
...

と変えてpushできるようになった。

~/Documents/freebsdPostInstall/.git/config

...
[remote "origin"]
        url = git@github:username/freebsdPostInstall.git
...

と変えてもloginできる。

しかし、なぜ以前はloginできてpushできていたのだろう。何も変えていないのに。単純に考えるとsshの振る舞いが変わったように思うが、この間バージョンアップはしてないはずなんだけど。もしかして忘れてるだけか。


自分向け追記 2021/01/27
このとき何が起きたのかは、依然としてわからないが、
GitHubでssh接続する手順~公開鍵・秘密鍵の生成から~ - Qiita
などをみると、

Host github github.com
  HostName github.com
  IdentityFile ~/.ssh/id_github_rsa
  User git

のように、Host 欄を書くほうが良いらしい。githubというエイリアスが必要ない場合は、github.comのみで問題ないと思うのだが。