CLOVER🍀

That was when it all began.

SSHポートフォワーディングで、リモートのXをローカルに転送する

X Window Systemに詳しくないのですが、リモートのXをローカルに転送するにはどうしたらいいのかな?と思いまして。

SSHポートフォワーディングで可能なようです。

リモートのSSHサーバーは、X11Forwardingyesになっている必要があります。
/etc/ssh/sshd_config

X11Forwarding yes

このオプションは、X11フォワーディングを許可するかどうかをyesnoで指定します。

X11Forwarding

特に理由がなければ、サーバーとしてはnoにしておくべきですね…。

ローカルは、SSH接続を行う時に-Xオプションを付与します。

$ ssh -X [接続先]

-Xオプションは、X11フォワーディングを許可します。

     -X      Enables X11 forwarding.  This can also be specified on a per-host basis in a configuration file.

             X11 forwarding should be enabled with caution.  Users with the ability to bypass file permissions on the remote host (for the user's X authorization database)
             can access the local X11 display through the forwarded connection.  An attacker may then be able to perform activities such as keystroke monitoring.

             For this reason, X11 forwarding is subjected to X11 SECURITY extension restrictions by default.  Please refer to the ssh -Y option and the ForwardX11Trusted di‐
             rective in ssh_config(5) for more information.

             (Debian-specific: X11 forwarding is not subjected to X11 SECURITY extension restrictions by default, because too many programs currently crash in this mode.  Set
             the ForwardX11Trusted option to “no” to restore the upstream behaviour.  This may change in future depending on client-side improvements.)

設定ファイルのオプション、ForwardX11yesにしたのと同等の効果です。

ForwardX11

設定ファイルは、/etc/ssh/ssh_configで全体に指定するか、$HOME/.ssh/configでホスト単位に指定することもできます。

ホスト単位に指定した場合。
$HOME/.ssh/config

Host [接続先]
    ForwardX11 yes

こうすると、設定した接続先にアクセスする場合は、-Xオプションは不要です(-Xを付与した状態になっています)。

$ ssh [接続先]

-Xを付与、もしくはForwardX11yesにした状態でSSH接続を行い、リモートでXを使用するアプリケーションを起動すると
ローカルに表示が転送されます。

接続先とネットワーク的に離れている場合は、-Cオプションを付与してもいいかもしれません。

$ ssh -CX [接続先]

転送するデータをgzip圧縮してくれます。

     -C      Requests compression of all data (including stdin, stdout, stderr, and data for forwarded X11, TCP and UNIX-domain connections).  The compression algorithm is
             the same used by gzip(1).  Compression is desirable on modem lines and other slow connections, but will only slow down things on fast networks.  The default
             value can be set on a host-by-host basis in the configuration files; see the Compression option.

Compressionyesにした時と同じですね。

Compression