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を見ればだいたい書いてある。
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.
xauthは通常インストールされているが、されていない場合インストールする必要がある。(サーバーサイド)
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 yuis@150.95.0.0
さらに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.
以下の手順に従えば問題ない。クライアントのconfigに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