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

[Linux] X_ネットワーク経由の利用_xhost, xauth, DISPLAY, ssh

Last updated at Posted at 2025-06-08

概要

コマンド 由来 役割
xhost X host access control X サーバへのアクセス制御をホスト単位で行う
xauth X authority X サーバへのアクセス制御をユーザー単位で行う

利用手順

ステップ 実行場所 コマンド例 説明
1 ホスト(表示側) xhost +192.168.0.2
xhost 192.168.0.2
リモートホストからの X 接続を許可
2 リモートホスト DISPLAY=192.168.0.1:0 X 出力先を指定(ホストの IP アドレス + ディスプレイ番号)
3 リモートホスト export DISPLAY 設定した DISPLAY を環境変数として有効化
4 リモートホスト xclock & GUI アプリケーションを起動し、表示側ホストに画面を転送

利用手順

1-a. ホスト(表示側)で xhost による接続許可

192.168.0.1(ホスト)
# 例: 192.168.0.2 がリモートホスト
$ xhost +192.168.0.2
$ xhost 192.168.0.2
  • 目的: 指定したリモートホストに、X サーバ(ローカルの画面)への接続を許可する
  • +のあとに ホスト名 またはIPアドレスを指定 (+は省略可)
  • セキュリティ上、可能ならば限定的に行う(xhost + は誰でも接続できて危険)

1-b. ホスト(表示側)でxauthによる接続許可(セキュアな方法)

192.168.0.1(ホスト)
# 現在の X 認証キーを確認
$ xauth list

# 例: UNIX:0  MIT-MAGIC-COOKIE-1  abcdef1234567890...

# ホストの MIT-MAGIC-COOKIE をファイルにエクスポート
$ xauth extract /tmp/xauthkey :0

# このファイルをリモートホストにコピー(scpなど)
$ scp /tmp/xauthkey user@192.168.0.2:/tmp/
  • 目的: より安全にX接続を認証ベースで制御する
  • xauthMIT-MAGIC-COOKIE-1認証方式を用いて、許可されたクライアントのみ接続を許可
  • xhostのようなホスト単位での全開放を避けられる

2. リモートホストで DISPLAY 環境変数を設定

192.168.0.2(リモートホスト)
# 例: 192.168.0.1 がホスト(表示側)
$ export DISPLAY=192.168.0.1:0
  • 目的: X アプリケーションが「どのディスプレイ(Xサーバ)」に出力すべきかを指定する
  • 192.168.0.1 はホスト(表示側)のIPアドレス
  • :0: 最初のディスプレイ番号
  • :1: 2番目のディスプレイ番号

3. リモートホストでXアプリケーションを起動

192.168.0.2(リモートホスト)
$ xclock &
  • 目的: アプリケーションのGUIを、ローカルの画面に表示
  • DISPLAY に設定されたアドレス宛てに描画要求が送られる

補足: ssh経由でより安全に行う方法(推奨)

# ホストから ssh -X でログイン(-Yは信頼できるX転送)
$ ssh -X user@192.168.0.2

# リモート側からGUIアプリを起動
$ xclock &
  • -X / -Y オプションで SSHが自動的にDISPLAYを設定 してくれる
  • xhost 不要、安全性が高い

Ping-t

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