Dragon Arrow written by Tatsuya Nakaji, all rights reserved animated-dragon-image-0164

EC2サーバーからGitHubにsshアクセスできない

updated on 2019-05-16

イメージ

EC2サーバーからGitHubにsshアクセスできない


仮想サーバーのフォルダやssh設定ファイル状況

[tatsuya@ip-10-0-0-238 .ssh]$ ls
GitHub  authorized_keys  config  known_hosts
[tatsuya@ip-10-0-0-238 .ssh]$ cd GitHub
[tatsuya@ip-10-0-0-238 GitHub]$ ls
aws_git_rsa  aws_git_rsa.pub
[tatsuya@ip-10-0-0-238 GitHub]$ cd ..
[tatsuya@ip-10-0-0-238 .ssh]$ cat config
Host github
  Hostname github.com
  User git
  Port 22
  IdentityFile ~/.ssh/GitHub/aws_git_rsa
[tatsuya@ip-10-0-0-238 .ssh]$ 

sshでGitHubに接続する

[tatsuya@ip-10-0-0-238 .ssh]$ ssh -T github
ssh: connect to host github.com port 22: Connection timed out


ファっ?! 

結構手こずったものの、原因は単純にEC2セキュリティグループのアウトバウンド設定でした(ーー;)

以下の画像のようにSSH接続の許可を出すと、無事接続できました。なお、ssh接続は今は任意の場所にしていますが、固定IPのルーターがある会社や組織などでは基本IPを指定して、他の場所からは接続できないようにするのが定石です。


[tatsuya@ip-10-0-0-238 .ssh]$ ssh github
Warning: Permanently added the RSA host key for IP address to the list of known hosts.
PTY allocation request failed on channel 0
Hi NakajiTatsuya! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

つながりました、完璧!!