4
2

More than 1 year has passed since last update.

Mac OS で ssh サーバーを踏み台にして SOCK プロクシ経由で Web ページにアクセスする例 ( #Mac #ssh )

Last updated at Posted at 2019-11-01

ssh コマンドでプロクシを起動する

  • 通常のsshコマンドと同じようにユーザー名、接続先のホスト、秘密鍵などを指定できる。
  • 途中で画面が止まるが、起動したままにしておく。プロクシサーバーみたいな扱いなので、起動したままが正しい。
ssh -vND 8888 user@xxx.xxx.xxx.xxx
ssh -vND 8888 user@xxx.xxx.xxx.xxx -i ~/.ssh/some.pem

Macの設定

セキュリティ > 詳細設定 に進む

image

image

プロクシのタブ

SOCKS proxy に localhost と ssh コマンドで指定したポート番号 を入力する。

http proxy や https proxy では動かないので注意。

image

OK を押して Apply を押す。
Macのこの画面って、Applyを忘れがちなので忘れずに。

GoogleChrome などでWebサイトにアクセスする

IPアドレスが変わっているのを確認する。

確認くん

image

コンソールにはアクセスログが流れてくる

image

他のアプリでも試してみる

OSレベルでproxyを利用しているので、どのアプリでもproxy経由でのアクセスになり、コンソールにログが流れてくる。

終了方法

Settings > Network > Advanced > Proxy のタブで チェックボックスを外して OK > Apply する

image

コマンド解説

ssh -v

饒舌モード。本体動作には関係ない。ログを細かく表示してくれるから動作が分かりやすくなる。

$ man ssh | cat | grep -A 10 '\-v'
     -v      Verbose mode.  Causes ssh to print debugging messages about its
             progress.  This is helpful in debugging connection, authentica-
             tion, and configuration problems.  Multiple -v options increase
             the verbosity.  The maximum is 3.

ssh -N

リモートホストでコマンドを実行しない。port forwadingにおすすめらしい。

$ man ssh | cat | grep -A 10 '\-N'
     -N      Do not execute a remote command.  This is useful for just for-
             warding ports.

ssh -D

portにアドレスをバインドする。

$ man ssh | cat | grep -A 10 '\-D'
     -D [bind_address:]port
             Specifies a local ``dynamic'' application-level port forwarding.
             This works by allocating a socket to listen to port on the local
             side, optionally bound to the specified bind_address.  Whenever a
             connection is made to this port, the connection is forwarded over
             the secure channel, and the application protocol is then used to
             determine where to connect to from the remote machine.  Currently
             the SOCKS4 and SOCKS5 protocols are supported, and ssh will act
             as a SOCKS server.  Only root can forward privileged ports.
             Dynamic port forwardings can also be specified in the configura-
             tion file.

参考

Setting up a SOCKS proxy in Mac OS X [StartupCTO]

Configure Proxy Settings - OS Level
Now, go into your Network Control Panel, and then 'Advanced…' → 'Proxies'. Set the SOCKS Proxy (only) with your proxy settings: localhost / 8888. You DO NOT want to set the HTTP proxy, HTTPS proxy, etc.

一方その頃、大坂梅田では稲川淳二の観覧車が回っていた

proxyサーバーを立てていたがために、妙なportで接続してしまったのか、異世界の踏み台に連れられていった男がひとり、いなかったとか、いたとか、いなかったとか。

image

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

4
2
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
4
2