Logical Rabbit.

さくらのVPS

pfsense

pfsenseをgatewayとした多段ssh。

ざっくり言うと、pfsenseのSSHログインを有効化+ProxyCommand+nc、といった具合。

[localhost(on the Internet)] -->[pfsense server] -->[target server(on the private network)]

参考にしたサイト

やりかた

pfsenseの設定

  1. pfsenseの管理画面にログイン、System >Advanced >Admin Access >Secure Shellに移動
  2. [Enable Secure Shell]をOnに
  3. 安全のため[Disable password login for Secure Shell (RSA/DSA key only)]をOnに
  4. [SSH port]を適当に指定(仮に114114とでもしておこうか)
  5. 以上でSave
  6. System >User Managerへ移動、Add Userを実行
  7. 冒頭のイメージ図で[localhost(on the Internet)]から[prsense server]へ接続するためのユーザを作成、Save
  8. 作成したユーザの編集画面を開き、[Effective Privileges]に[User - System - Shell account access]を追加
  9. [Authorized keys]にの公開鍵を追記
  10. 以上でSave
  11. Firewall >Rulesに移動、Rule追加を実行
  12. [Destination]を[WAN]に、[Destination port range]に114114を指定
  13. 以上をSaveし、さらにApply change実行

pfsenseの設定は以上で完了。必要に応じ[localhost(on the Internet)]から[pfsense server]にsshログインできることを確認。

クライアント・サーバー(接続先)の設定

  1. [localhost(on the Internet)]の公開鍵を[target server(on the private network)]の.ssh/authorized_keysに登録
  2. .ssh/configを以下のように記述
    Host gateway
    HostName pfsense_server
    Port 114114
    Host target
    HostName target_server
    ProxyCommand /usr/bin/ssh gateway /usr/bin/nc %h %p
    

.ssh/authorized_keys、.ssh/configのパーミッションには注意すること。

以上を実施のうえ、次のようにsshコマンドを実行することで[pfsense server]を介して[target server(on the private network)]に接続できるようになる。sshの他scp、sftpも使用可能。

[localhost(on the Internet)]$ ssh target_server