はじめに

GitHubへの接続にて、SSHポート(22)が使用できない場合に、HTTPS(443)ポートを使いつつ、SSHでの接続をしたいという要件があった。
これを解決したいので調査してみる。

環境

1
2
Windows 10 Professional
WSL2 (Ubuntu22.04 LTS)

準備

鍵の作成

まずは、ssh の接続をできるように、SSHの鍵ファイルを作成する。

1
$ ssh-keygen
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
Generating public/private rsa key pair.
Enter file in which to save the key (/home/[ユーザ名]/.ssh/id_rsa):
Created directory '/home/[ユーザ名]/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/[ユーザ名]/.ssh/id_rsa
Your public key has been saved in /home/[ユーザ名]/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:UB3H2t4F5cynGIKlnnUD7qPzQgAoaFQZSsg8lHpSLt4 [ユーザ名]@[PC名]
The key's randomart image is:
+---[RSA 3072]----+
|B+o+o   ..+o.  ..|
|=*+..  . =.o. .+ |
|o=.  .. o +o+  .=|
|+ o   .o +.o.+ .o|
|.+.    .S o..... |
| . E    .. .. .  |
|       .o        |
|        .o       |
|         ..      |
+----[SHA256]-----+

これで、 /home/[ユーザ名]/.ssh/id_rsa に鍵ファイルが作成される。

GitHubへの接続を試す

SSHでの接続テスト

1
[email protected]: Permission denied (publickey).

どうやら鍵ファイルの権限になにか問題があるのか? 調査してみる。

参考: https://docs.github.com/en/authentication/troubleshooting-ssh/error-permission-denied-publickey?platform=linux

下記に問題があったようだ

  • GitHub に公開鍵を登録し忘れていた。

というわけなので、公開鍵(id_rsa.pub)を GitHubのSSH and GPG keysに登録する。
SSH keysAuthentication Kyes に登録をした。

再度 SSHでの接続テスト

1
2
3
$ ssh -T [email protected]

Hi katsuobushiFPGA! You've successfully authenticated, but GitHub does not provide shell access.

うまく行ったようだ。

HTTPSのポートでSSHの接続

1
ssh -T -p 443 [email protected]
1
2
3
4
5
6
7
8
$ ssh -T -p 443 [email protected]
The authenticity of host '[ssh.github.com]:443 ([20.27.177.118]:443)' can't be established.
ED25519 key fingerprint is [フィンガープリント]
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: [hashed name]
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[ssh.github.com]:443' (ED25519) to the list of known hosts.
Hi katsuobushiFPGA! You've successfully authenticated, but GitHub does not provide shell access.

おぉ~いけますね。

参考

おわりに

22番ポートがアウトバウンドで許可されていない場合は、HTTPS(443)でのポートでも接続ができるということを頭に入れておきたい。