1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows標準のssh.exeではX11のDISPLAYが自動設定されない

Posted at

ある日のこと

X11使いたいなと思ったある日、早速使ってみることにした。
だがどうやっても繋がらない

echo $DISPLAY

空っぽ...

おいAI!どうしたらいいか教えてくれ
???「xauthガインストールサレテイルカカクニンシテクダサイジドウデセッテイサレマス」

数分後...
わい「全然できねえんだけどなんかgitbashならいけたわ。なんでなん」
???「エ?」

実はWindows標準のssh.exeはX11には対応しているが自動でDISPLAYを設定してくれない

わい「頼むから対応してくれ。他のsshよりssh.exeが好きなんだ」

解決策

.bashrcに以下のスクリプトを書き込みます。

#X11Forwarding
if [[ -n "$SSH_CONNECTION" && -z "$DISPLAY" ]]; then
    # クライアントIPアドレスを取得
    CLIENT_IP=$(echo $SSH_CONNECTION | awk '{print $1}')
    
    # Windows クライアントからで DISPLAY が自動設定されない場合は :0 が多い
    # 仮に :0 を使いたい場合:
    export DISPLAY="$CLIENT_IP:0"
fi

これでホスト側の設定ができました!

VcXsrvを起動し忘れないようにね

「よっしゃ!SSH接続してqemuでOS動かすぜ!」

ssh -X jun@192.168.100.2
1
0
1

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?