LoginSignup
3
1

[Windows] Proxyサーバー経由でSSH接続してみてみた

Last updated at Posted at 2024-03-12

UNIX形OSでは ncコマンドを使用して Proxy経由が必要なインスタンスへssh接続できます。
・参考: ncコマンドを使用して Proxy経由でSSH接続
nc (netcat)コマンドは、TCP または UDP に関連付けられた様々なタスクに使用できます。
宛先を指定して対象ホストに接続するだけでなく、自らがサーバーになりコネクションを待ち受けるなど、さまざまな通信を行うことができます。
nc コマンドは、多くの場合、次のタスクに使用されます。

・ 単純な TCP プロキシ
・ シェルスクリプトベースの HTTP クライアントおよびサーバー
・ ネットワークデーモンのテスト
・ ssh(1) 用の SOCKS または プロキシコマンド (ProxyCommand)

Windowsでは、ncコマンドの代わりに Git Bash付属の Mingw-w64 に含まれている connect.exe を利用して SSHコマンドを利用して Proxy経由でSSH接続ができます。
ということで、connect.exe を使用して Proxyサーバー経由が必要なインスタンスへ ssh接続してみてみます。

■ Git インストール

connect.exe を取得するために Git をインストールします。

1) git Download
https://git-scm.com/ から git をダウンロード
01.png

2) git インストーラー実行
ダウンロードしたインストーラーEXEをダブルクリック
02.png

3) git インストール
Git Setup画面でセットアップしていきます。
03.png

4) git インストール完了
19.png

5) connect.exe ファイル確認
gitインストール完了後、gitインストールディレクトリに C:\Program Files\Git\mingw64\bin\connect.exe があることを確認

PS C:\Users\oracle> dir "C:\Program Files\Git\mingw64\bin\connect.exe"

        ディレクトリ: C:\Program Files\Git\mingw64\bin


    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    -a----        2024/02/23     20:23          84766 connect.exe

■ Proxy 経由で SSH接続

1) ~/.ssh/config ファイル設定
ssh接続が Proxy経由になるようにログインユーザーのホームディレクトリにある .ssh/config ファイルへProxyCommandパラメータを次のように設定、他のパラメータはおまけです。
・参考: ssh_config(5) — Linux manual page

PS C:\Users\oracle> cat ~\.ssh\config
    Host *
        ProxyCommand C:\Program Files\Git\mingw64\bin\connect.exe -H {ProxyサーバーのURL}:{ポート番号} %h %p
        ServerAliveInterval 30
        ServerAliveCountMax 120


PS C:\Users\oracle> ls ~\.ssh

        ディレクトリ: C:\Users\oracle\.ssh


    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    -a----        2024/03/12     12:08            245 config
    -a----        2024/03/12     12:06           1807 id_rsa

2) ssh 実行
Proxyサーバー経由が必要なインスタンスへ ssh接続できることを確認

PS C:\Users\oracle> ssh opc@<インスタンスIPアドレス>
    The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't be established.
    ECDSA key fingerprint is SHA256:zQG7/5cue4jaetyk8JFZFD+76Zqv1vj.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added 'xxx.xxx.xxx.xxx' (ECDSA) to the list of known hosts.
    Activate the web console with: systemctl enable --now cockpit.socket

[opc@tokyo-inst01 ~]$ hostname
    tokyo-inst01

■ 参考

 ・ nc ユーザーコマンド
 ・ ssh_config(5) — Linux manual page
 ・ manページ — SSH_CONFIG
 ・ git

3
1
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
3
1