Linuxパソコン・サーバーおよびWindows上のWSL Linux Bash環境を通して、Linux->WSL->Windows X11フォワーディングでGUIアプリを開く方法について紹介します。
conoha vpsに対して、wsl経由でwindowsからSSHしてconohaで起動したgeditをWindowsで編集してみます。
手順
xorg - How to forward X over SSH to run graphics applications remotely? - Unix & Linux Stack Exchangeを見ればだいたい書いてある。
xauthは通常インストールされているが、されていない場合インストールする必要がある。(サーバーサイド)Your client must be set up to forward X11. Your server must be set up to allow X11 forwarding. Your server must be able to set up X11 authentication.
type xauth
クライアントサイドにて以下を~/.ssh/configへ記述。
sublime_text ~/.ssh/config
Host *
ForwardAgent yes
ForwardX11 yes
XAuthLocation /usr/bin/xauth
ForwardX11Trusted yes
サーバーサイドのsshd_configファイルにX11Forwarding yesの記述があるかどうか。なければ追記。普通ある。
cat /etc/ssh/sshd_config | fzf
クライアントからsshで接続してやる。-Xをつける。-v(verbose)オプションもデバッグ目的で推奨されている。
WSLからconohaのVPSに接続する例: ssh -v -X -L 4000:localhost:4000 -R 52698:localhost:52698 [email protected]
さらにWSLからwindowsへ渡すには、X SERVERソフトウェアを使う。
Xming X Server for Windows download | SourceForge.net
xmingというソフトウェアを落としてインストール。
で、デフォルトだとポート0:0で起動されるので、.bashrcへ以下を追記。
export DISPLAY=localhost:0.0
複数起動とかエラー*1 が原因でポートを1,2などに変えた場合は上のコードも変える。
1: 別途記事でも紹介しているがバグが多い。更新もされてないみたいだけど選択肢がないので。tail -f “xming.0.log”推奨。
sshなしでgeditをWSLでしてみて、windowsにレンダリングされるか確認してみると良い。その上でover sshでgeditして、WSL経由でgeditが表示されればOKです。
(WSL経由推してますが VPS -> windows(powershell)でも行けると思います。)
known errors
- No xauth data; using fake authentication data for X11 forwarding.
XAuthLocation /usr/bin/xauthが無いと起こる
[SOLVED] Problem with “Warning: No xauth data; using fake authentication data for X11 forwarding.”
- Bad owner or permissions on /home/yuis/.ssh/config
sudo chmod 600 ~/.ssh/config