@itagagaki (板垣 史彦)

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

WSL2 Ubuntu にホストWindowsからRDP接続したい

解決したいこと

質問 Windows 11 WSL2 (Ubuntu) のIPアドレスとxrdp の続きです。

Winows 11 Pro 25H2 で WSL2 を有効化して Ubuntu 24.04.3 LTS (Noble Numbat) をインストールし、ネットワークモードは Nat で稼働させています。そこまでの経緯は上記の質問にあります。

WSL Settings のネットワークモードが Nat なので、Ubuntu ではホストの Windows と異なる IPv4 アドレスとなっています。そこで、この Ubuntu で xrdp を動かし、ホストの Windows のリモートデスクトップ接続 (mstsc.exe) で、Ubuntu の IPv4 アドレスを指定して接続してみたい。

xrdp を稼働させるまでの手順は下記のように行いました。

sudo apt update
sudo apt upgrade
sudo apt install ubuntu-desktop
sudo apt install xrdp
sudo adduser xrdp ssl-cert
sudo systemctl restart xrdp

RDP接続は下記の手順で試しました。

  1. Ubuntu からログアウト
  2. Windows で リモートデスクトップ接続 を実行

発生している問題・エラー

リモートデスクトップ接続 を実行して Ubuntu の IPv4 アドレスを入力すると、ウィンドウが開いてログイン画面は出るのですが、数秒後にウィンドウが勝手に閉じてしまい、ログインが不可能です。

そこで Ubuntu にコンソールでログインして、ログを見てみました。

/var/log/xrdp.log
[20251227-20:39:43] [INFO ] address [0.0.0.0] port [3389] mode 1
[20251227-20:39:43] [INFO ] listening to port 3389 on 0.0.0.0
[20251227-20:39:43] [INFO ] xrdp_listen_pp done
[20251227-20:39:45] [INFO ] starting xrdp with pid 26744
[20251227-20:39:45] [INFO ] address [0.0.0.0] port [3389] mode 1
[20251227-20:39:45] [INFO ] listening to port 3389 on 0.0.0.0
[20251227-20:39:45] [INFO ] xrdp_listen_pp done
[20251227-20:40:09] [INFO ] Received termination signal, stopping the server accept new connections thread
[20251227-20:40:09] [INFO ] address [0.0.0.0] port [3389] mode 1
[20251227-20:40:09] [INFO ] listening to port 3389 on 0.0.0.0
[20251227-20:40:09] [INFO ] xrdp_listen_pp done
[20251227-20:40:11] [INFO ] starting xrdp with pid 26830
[20251227-20:40:11] [INFO ] address [0.0.0.0] port [3389] mode 1
[20251227-20:40:11] [INFO ] listening to port 3389 on 0.0.0.0
[20251227-20:40:11] [INFO ] xrdp_listen_pp done
[20251227-20:40:46] [INFO ] Socket 12: AF_INET6 connection received from ::ffff:172.28.192.1 port 54359
[20251227-20:40:46] [INFO ] Using default X.509 certificate: /etc/xrdp/cert.pem
[20251227-20:40:46] [INFO ] Using default X.509 key file: /etc/xrdp/key.pem
[20251227-20:40:46] [INFO ] Security protocol: configured [SSL|RDP], requested [SSL|HYBRID|HYBRID_EX|RDP], selected [SSL]
[20251227-20:40:46] [ERROR] SSL_read: I/O error
[20251227-20:40:46] [ERROR] libxrdp_force_read: header read error
[20251227-20:40:46] [ERROR] Processing [ITU-T T.125] Connect-Initial failed
[20251227-20:40:46] [ERROR] [MCS Connection Sequence] receive connection request failed
[20251227-20:40:46] [ERROR] xrdp_sec_incoming: xrdp_mcs_incoming failed
[20251227-20:40:46] [ERROR] xrdp_rdp_incoming: xrdp_sec_incoming failed
[20251227-20:40:46] [ERROR] xrdp_process_main_loop: libxrdp_process_incoming failed
[20251227-20:40:46] [ERROR] xrdp_iso_send: trans_write_copy_s failed
[20251227-20:40:46] [ERROR] Sending [ITU T.125] DisconnectProviderUltimatum failed
[20251227-20:40:48] [INFO ] Socket 12: AF_INET6 connection received from ::ffff:172.28.192.1 port 54361
[20251227-20:40:48] [INFO ] Using default X.509 certificate: /etc/xrdp/cert.pem
[20251227-20:40:48] [INFO ] Using default X.509 key file: /etc/xrdp/key.pem
[20251227-20:40:48] [INFO ] Security protocol: configured [SSL|RDP], requested [SSL|HYBRID|HYBRID_EX|RDP], selected [SSL]
[20251227-20:40:48] [INFO ] Connected client computer name: BLUE
[20251227-20:40:48] [WARN ] Received [MS-RDPBCGR] TS_UD_HEADER type 0xc006 is unknown (ignored)
[20251227-20:40:48] [WARN ] Received [MS-RDPBCGR] TS_UD_HEADER type 0xc00a is unknown (ignored)
[20251227-20:40:48] [INFO ] xrdp_load_keyboard_layout: Keyboard information sent by the RDP client, keyboard_type:[0x04], keyboard_subtype:[0x00], keylayout:[0xE0010411]
[20251227-20:40:48] [INFO ] xrdp_load_keyboard_layout: model [] variant [] layout [jp] options []
[20251227-20:40:48] [INFO ] TLS connection established from ::ffff:172.28.192.1 port 54361: TLSv1.3 with cipher TLS_AES_256_GCM_SHA384
[20251227-20:40:48] [INFO ] xrdp_caps_process_pointer: client supports new(color) cursor
[20251227-20:40:48] [INFO ] xrdp_process_offscreen_bmpcache: support level 1 cache size 7864320 MB cache entries 100
[20251227-20:40:48] [INFO ] xrdp_caps_process_codecs: nscodec, codec id 1, properties len 3
[20251227-20:40:48] [WARN ] xrdp_caps_process_codecs: unknown codec id 5
[20251227-20:40:48] [WARN ] Cannot find keymap file /etc/xrdp/km-e0010411.ini
[20251227-20:40:48] [INFO ] Loading keymap file /etc/xrdp/km-00000411.ini
[20251227-20:40:48] [WARN ] local keymap file for 0xe0010411 found and doesn't match built in keymap, using local keymap file
[20251227-20:40:51] [INFO ] Received termination signal, stopping the server accept new connections thread
[20251227-20:41:12] [INFO ] address [0.0.0.0] port [3389] mode 1
[20251227-20:41:12] [INFO ] listening to port 3389 on 0.0.0.0
[20251227-20:41:12] [INFO ] xrdp_listen_pp done
[20251227-20:41:14] [INFO ] starting xrdp with pid 544
[20251227-20:41:14] [INFO ] address [0.0.0.0] port [3389] mode 1
[20251227-20:41:14] [INFO ] listening to port 3389 on 0.0.0.0
[20251227-20:41:14] [INFO ] xrdp_listen_pp done

[ERROR] がありますね。
いろいろ検索して調べましたが、まだどのエラーも原因がつかめません。
何か情報がありましたらご教授いただければ幸いです。

0 likes

1Answer

/var/log/xrdp.log[ERROR]は関係ないようです。デスクトップ環境xfce4をインストールしてRDPしてみましたが、まったく同じ内容の[ERROR]が出ていました。

xfce4は次のコマンドでインストールしました。

sudo apt install -y xrdp xfce4 xfce4-goodies

# ログイン時にXfceを起動する設定
echo "xfce4-session" > ~/.xsession

# xrdpサービスを起動・有効化
sudo systemctl enable xrdp
sudo systemctl start xrdp

自分の環境でもubuntu-desktopではRDPできませんでした。

1Like

Comments

  1. @itagagaki

    Questioner

    ありがとうございます

    ubuntu-desktop をremoveして、教えていただいたとおりにしてみましたが、ウィンドウが閉じてしまうのは変わらず、でした。

    ウィンドウが閉じてしまうまでの時間は一定ではなく、1秒未満のときもあれば、6秒くらい後に閉じることもあります。

    そこで、ウィンドウが閉じてしまう前に、頑張ってユーザー名とパスワードを入力して、間に合ったら、ようやくデスクトップまでたどり着きました。

    が、成功したのはその一度きりで、その後は何度試しても、真っ黒の画面の中に以下の表示が出て、やはり数秒後にmstsc.exeのウィンドウが閉じてしまいます。

    image.png

    この表示が出る前に落ちてしまうこともあります。

    systemsettings5 とやらはどこにあるのでしょう。見つかりませんでした。

    /var/log/xrdp-sesman.log を見ると、このようになっていました。

    /var/log/xrdp-sesman.log
    [20251229-03:10:05] [INFO ] sesman_main_loop: sesman asked to terminate
    [20251229-03:10:05] [INFO ] starting xrdp-sesman with pid 728
    [20251229-03:11:00] [INFO ] Socket 12: AF_INET6 connection received from ::1 port 47544
    [20251229-03:11:00] [INFO ] Terminal Server Users group is disabled, allowing authentication
    [20251229-03:11:00] [INFO ] ++ created session (access granted): username ita, ip ::ffff:172.28.192.1:49407 - socket: 12
    [20251229-03:11:00] [INFO ] starting Xorg session...
    [20251229-03:11:00] [INFO ] Starting session: session_pid 752, display :10.0, width 3840, height 2160, bpp 24, client ip ::ffff:172.28.192.1:49407 - socket: 12, user name ita
    [20251229-03:11:00] [INFO ] [session start] (display 10): calling auth_start_session from pid 752
    [20251229-03:11:00] [ERROR] sesman_data_in: scp_process_msg failed
    [20251229-03:11:00] [ERROR] sesman_main_loop: trans_check_wait_objs failed, removing trans
    [20251229-03:11:01] [INFO ] Starting X server on display 10: /usr/lib/xorg/Xorg :10 -auth .Xauthority -config xrdp/xorg.conf -noreset -nolisten tcp -logfile .xorgxrdp.%s.log
    [20251229-03:11:01] [INFO ] Found X server running at /tmp/.X10-lock
    [20251229-03:11:01] [INFO ] Found X server running at /tmp/.X10-lock
    [20251229-03:11:01] [INFO ] Session started successfully for user ita on display 10
    [20251229-03:11:01] [INFO ] Session in progress on display 10, waiting until the window manager (pid 753) exits to end the session
    [20251229-03:11:01] [INFO ] Starting the xrdp channel server for display 10
    [20251229-03:11:01] [INFO ] Found X server running at /tmp/.X10-lock
    [20251229-03:11:01] [INFO ] Starting the default window manager on display 10: /etc/xrdp/startwm.sh
    [20251229-03:11:02] [WARN ] Window manager (pid 753, display 10) exited with non-zero exit code 255 and signal 15. This could indicate a window manager config problem
    [20251229-03:11:02] [WARN ] Window manager (pid 753, display 10) exited quickly (1 secs). This could indicate a window manager config problem
    [20251229-03:11:02] [INFO ] Calling auth_stop_session and auth_end from pid 752
    [20251229-03:11:02] [INFO ] Terminating X server (pid 754) on display 10
    [20251229-03:11:02] [INFO ] Terminating the xrdp channel server (pid 762) on display 10
    [20251229-03:11:02] [INFO ] X server on display 10 (pid 754) returned exit code 0 and signal number 0
    [20251229-03:11:02] [INFO ] xrdp channel server for display 10 (pid 762) exit code 255 and signal number 1
    [20251229-03:11:02] [INFO ] cleanup_sockets:
    [20251229-03:11:02] [INFO ] sesman_main_loop: sesman asked to terminate
    [20251229-03:11:30] [INFO ] starting xrdp-sesman with pid 378
    

    どうやらウィンドウマネージャーの設定に問題がありそうですね…

  2. systemsettings5 とやらはどこにあるのでしょう。見つかりませんでした。

    systemsettings5,systemsettings は、KDE Plasma デスクトップ環境における「システム設定」アプリケーションの実行コマンド名です。

    ・・・らしいです。

    ubuntu-desktop をremoveして、教えていただいたとおりにしてみましたが、ウィンドウが閉じてしまうのは変わらず

    自分は、Ubuntu自体を再インストールして先の手順にてxfce4にしました。そのときはスンナリ接続できたのですが、本日再度試すと、スクショと同じエラーになってしまいました。もう少し調べてみます。すみません。

  3. @itagagaki

    Questioner

    いろいろと、お骨を折っていただき、ありがとうございます
    なかなか道が険しいですね…
    不安定な要素も多い印象です

  4. 次のコマンドにて、現在どのマネージャーが動いているか(あるいは動いていないか)を確認できるでしょうか?

    # どのマネージャーがアクティブか確認
    cat /etc/X11/default-display-manager
    

    また、下記ファイル(直近)に、エラーが出ているでしょうか?

    cat ~/.xsession-errors
    
  5. おそらく、以下の対応で、XfceデスクトップへRDPできると思います。

    はじめに、これまでのゴミ掃除(Ubuntuクリーンインストール直後であれば不要)

    # xrdpを一旦停止
    sudo systemctl stop xrdp
    
    # 関連プロセスをすべてkill
    sudo pkill -u $USER
    sudo pkill Xorg
    sudo pkill xrdp
    
    # ロックファイルとソケットを根こそぎ削除
    sudo rm -rf /tmp/.X11-unix/X10
    sudo rm -rf /tmp/.X10-lock
    sudo rm -rf /var/run/xrdp/*
    
    # 一時的なセッションファイルを削除
    rm -rf ~/.cache/sessions/*
    rm -rf ~/.dbus/session-bus/*
    
    rm -rf ~/.xsession ~/.xsessionrc ~/.xsession-errors
    rm -rf ~/.cache/sessions ~/.config/xfce4 ~/.Xauth
    

    続いて、Xfceデスクトップの設定。
    (設定済みと思われるところはコメント化)

    # パッケージの更新
    #sudo apt update && sudo apt upgrade -y && sudo apt clean && sudo apt autoremove -y
    
    # Xfce4デスクトップ環境とxrdpのインストール
    #sudo apt install -y xrdp xfce4 xfce4-goodies
    
    # xrdpの起動スクリプトを「Xfce直起動」に書き換える
    sudo bash -c 'cat << EOF > /etc/xrdp/startwm.sh
    #!/bin/sh
    if [ -r /etc/default/locale ]; then
      . /etc/default/locale
      export LANG LANGUAGE
    fi
    
    # 環境変数をクリアしX11とXfceを明示
    unset WAYLAND_DISPLAY
    unset XDG_RUNTIME_DIR
    export XDG_SESSION_TYPE=x11
    export XDG_CURRENT_DESKTOP=XFCE
    export LIBGL_ALWAYS_SOFTWARE=1
    
    # D-Busを確実に生成してXfceを起動
    exec dbus-run-session -- xfce4-session
    EOF'
    
    # 実行権限の付与
    sudo chmod +x /etc/xrdp/startwm.sh
    
    # SSL証明書へのアクセス権限を付与
    #sudo adduser xrdp ssl-cert
    

    Xwrapperの設定変更
    (適用なエディタで/etc/X11/Xwrapper.configを編集)

    # Xwrapper.configを編集(ex, `sudo vim /etc/X11/Xwrapper.config`
    allowed_users=console という行を allowed_users=anybody に書き換える(なければ追加)
    次の1行を追加
    
    needs_root_rights=yes
    

    XRDP再起動

    # xrdpサービスの有効化&再起動
    #sudo systemctl enable xrdp
    sudo systemctl restart xrdp
    

    ローカルにログインしたまま、Windows11からRDPする。
    どうでしょうか。

  6. @itagagaki

    Questioner

    /etc/X11/default-display-manager の内容は /usr/sbin/lightdm でした。

    .xsession-errors の内容は

    Xsession: X session started for ita at Mon Dec 29 03:11:01 JST 2025
    dbus-update-activation-environment: setting DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
    dbus-update-activation-environment: setting DISPLAY=:10.0
    localuser:ita being added to access control list
    dbus-update-activation-environment: setting QT_ACCESSIBILITY=1
    dbus-update-activation-environment: setting USER=ita
    dbus-update-activation-environment: setting XDG_SESSION_TYPE=x11
    dbus-update-activation-environment: setting HOME=/home/ita
    dbus-update-activation-environment: setting XRDP_PULSE_SINK_SOCKET=xrdp_chansrv_audio_out_socket_10
    dbus-update-activation-environment: setting XRDP_PULSE_SOURCE_SOCKET=xrdp_chansrv_audio_in_socket_10
    dbus-update-activation-environment: setting DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
    dbus-update-activation-environment: setting PULSE_SCRIPT=/etc/xrdp/pulse/default.pa
    dbus-update-activation-environment: setting IM_CONFIG_PHASE=1
    dbus-update-activation-environment: setting LOGNAME=ita
    dbus-update-activation-environment: setting GTK_IM_MODULE=ibus
    dbus-update-activation-environment: setting XDG_SESSION_CLASS=user
    dbus-update-activation-environment: setting PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
    dbus-update-activation-environment: setting XRDP_SOCKET_PATH=/run/xrdp/sockdir
    dbus-update-activation-environment: setting XDG_RUNTIME_DIR=/run/user/1000
    dbus-update-activation-environment: setting DISPLAY=:10.0
    dbus-update-activation-environment: setting LANG=C.UTF-8
    dbus-update-activation-environment: setting XMODIFIERS=@im=ibus
    dbus-update-activation-environment: setting UID=1000
    dbus-update-activation-environment: setting SHELL=/bin/bash
    dbus-update-activation-environment: setting QT_ACCESSIBILITY=1
    dbus-update-activation-environment: setting XRDP_SESSION=1
    dbus-update-activation-environment: setting GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
    dbus-update-activation-environment: setting QT_IM_MODULE=ibus
    dbus-update-activation-environment: setting PWD=/home/ita
    dbus-update-activation-environment: setting XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share:/usr/share:/var/lib/snapd/desktop
    dbus-update-activation-environment: setting CLUTTER_IM_MODULE=ibus
    _IceTransmkdir: ERROR: euid != 0,directory /tmp/.ICE-unix will not be created.
    /usr/bin/iceauth:  creating new authority file /run/user/1000/ICEauthority
    xfce4-session-Message: 03:11:01.573: SSH authentication agent is already running
    gpg-agent: a gpg-agent is already running - not starting a new one
    
    (xfwm4:959): Gtk-WARNING **: 03:11:01.640: cannot open display: wayland-0
    
    (xfsettingsd:960): dbind-WARNING **: 03:11:01.678: Could not open X display
    
    (xfce4-panel:975): dbind-WARNING **: 03:11:01.947: Could not open X display
    xfce4-panel-Message: 03:11:01.981: Unable to open display from environment variable DISPLAY='wayland-0', exiting.
    
    (Thunar:982): dbind-WARNING **: 03:11:02.015: Could not open X display
    

    DISPLAY='wayland-0' をどうにかしないといけないのでしょうかね。

  7. DISPLAY='wayland-0' をどうにかしないといけないのでしょうかね。

    先ほど回答した「# xrdpの起動スクリプトを「Xfce直起動」に書き換える」に含んでいます。

  8. @itagagaki

    Questioner

    教えていただいた対応をなぞったら、無事、安定的にRDP接続できるようになりました!
    しかもコンソールでログインしたままでOKなんですね。
    助かりました。ありがとうございました。

  9. しかもコンソールでログインしたままでOKなんですね。

    本来はログインせずともRDPできるはずなんですが、その方法が いまだ分かっていません。その状態でRDPすると、Xfceデスクトップが出て数秒で消えてしまいます。

  10. @itagagaki

    Questioner

    本当ですね。
    手元には mstsc.exe の他に別のRDPクライアントがあるので、それにユーザー名とパスワードを登録し、ログアウトした状態で接続してみると、やはり接続がエラーとなり、このクライアントではリトライを繰り返す動作をします。その間にコンソールでログインしてみると、次のリトライで成功してウィンドウが正常に開きました。

Your answer might help someone💌