LoginSignup
42
14

More than 3 years have passed since last update.

githubでssh: connect to host github.com port 22エラーが発生した

Last updated at Posted at 2021-01-07

私は普段githubにはsshで接続を行っているのですが、port22で接続できないネットワーク環境の際にgithubと通信を行うとエラーが発生しました。
その時の対処法。

何が起こったか

カフェのWIFIにつないでgithubにいつもどおりアクセスしようとしたところ下記のエラーが発生した。

$ git push origin master
ssh: connect to host github.com port 22: Operation timed out
fatal: Could not read from remote repository.

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

どうやらここのWIFIはport22での接続を許容していないらしい。

port443でssh接続を行う

対処法はこちらの公式ドキュメントに書いてあるままなのですが、以下の手順で行いました。

接続できるか確認。

$ ssh -T -p 443 git@ssh.github.com
The authenticity of host '[ssh.github.com]:443 ([18.181.13.223]:443)' can't be established.
RSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[ssh.github.com]:443,[18.181.13.223]:443' (RSA) to the list of known hosts.
Hi username! You've successfully authenticated, but GitHub does not provide shell access.

configを公式に従って編集

$ vi ~/.ssh/config

//以下を記載して保存
Host github.com
   User git
   Hostname ssh.github.com
   Port 443
   IdentityFile ~/.ssh/id_rsa

ssh接続を確認する

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

できました〜〜〜〜!

セキュリティ的な問題とか

この辺よくわからんかったので、@mikkame さんに聞きました。

原理上はHTTPSを使っているわけではなく、HTTPSのportを使ってssh接続をしているだけなので問題が起こる可能性は限りなく低いとのことです。

なので、configファイルはこのままでも問題なさそうでしたが、なんとなく自宅で接続する際に不要なものが含まれてるのも気持ち悪いので、そのカフェを出る際にconfigファイルは元の設定に戻しました。

@mikkame さんSpecial Thanks!:pray: :pray: :pray:

42
14
1

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
42
14