xrdpでログインするとRDPが落ちる



ここ数年悩んでいた問題がついに解決できたので備忘としてまとめます

# 現象の再現手順
* epelから取得したxrdpがインストールされているAlmalinux8サーバをrunlevel5で起動
* コンソールからrootユーザーでログインする
* windows10のクライアント端末からrdpでalmalinux8サーバにログインを行う
* 認証画面が表示されるのでユーザー名：root、パスワードを入力しログインする
* windows10のrdpが突然落ちる

（これまでの回避方法）
* サーバを再起動する
* コンソールでrootユーザーでログインをしない
* windows10のrdpでログインできる
* またはコンソールでログインしていないユーザーを使ってrdp接続はできるので、rootでやりたいことはsudoコマンドで実行する

再起動の手順が入るので止められないときはしんどい。

## 以下出力されたログ

/var/log/xrdp.logは特段何もエラーを出力していなかったので割愛

``` /var/log/xrdp-sesman.log
 [INFO ] Socket 13: connection accepted from AF_UNIX
 [INFO ] Received system login request from xrdp for user: root IP: ::ffff:192.168.102.44
 [DEBUG] Closed socket 13 (AF_UNIX)
 [DEBUG] Calling exec (excutable: /usr/libexec/xrdp/xrdp-sesexec, arguments: xrdp-sesexec)
 [WARN ] Obsolete setting' ListenAddress' in [Globals] should be removed.
 [WARN ] Review setting' ListenPort' in [Globals]
 [WARN ] Ignoring obsolete SCP port value '3350'
 [INFO ] starting xrdp-sesexec with pid 692494
 [INFO ] TerminalServerUsers group tsusers doesn't exist. Access granted for root
 [INFO ] Access permitted for user: root
 [DEBUG] Closed socket 9 (AF_UNIX)
 [INFO ] Received sys login status for root : logged in
 [INFO ] Received request from xrdp to create a session for user root
 [DEBUG] session_list_get_bydata: search policy=UB type=Xvnc U=0 B=32 D=(1920x1080) I=::ffff:192.168.102.44
 [DEBUG] session_list_get_bydata: No matches found
 [INFO ] Found X server running at /tmp/.X11-unix/X10
 [DEBUG] Did not find a running X server at /tmp/.X11-unix/X11
 [DEBUG] Did not find a running X server at /tmp/.X11-lock
 [DEBUG] Closed socket 15 ([::]:5911)
 [DEBUG] Did not find a running X server at 5911
 [DEBUG] Closed socket 15 ([::]:6011)
 [DEBUG] Did not find a running X server at 6011
 [DEBUG] Closed socket 15 ([::]:6211)
 [DEBUG] Closed socket 13 (AF_UNIX)
 [DEBUG] Waiting for X server to start on display :11
 [DEBUG] Calling exec (excutable: /usr/libexec/xrdp/waitforx, arguments: /usr/libexec/xrdp/waitforx -d :11)
 [INFO ] Starting X server on display 11: Xvnc :11 -auth .Xauthority -geometry 1920x1080 -depth 32 -rfbauth /root/.vnc/sesman_passwd-root@linuxserver:11 -bs -nolisten tcp -localhost -dpi 96
 [DEBUG] waitforx: Opening display :11. Attempt 1 of 10
 [DEBUG] Calling exec (excutable: Xvnc, arguments: Xvnc :11 -auth .Xauthority -geometry 1920x1080 -depth 32 -rfbauth /root/.vnc/sesman_passwd-root@linuxserver:11 -bs -nolisten tcp -localhost -dpi 96)
 [DEBUG] waitforx: Opening display :11. Attempt 2 of 10
 [DEBUG] waitforx: Opened display :11
 [DEBUG] waitforx: Waiting for outputs. Attempt 1 of 10
 [DEBUG] waitforx: Display :11 ready with 1 RandR outputs
 [DEBUG] waiting for pid 692499 to exit
 [INFO ] X server :11 is working
 [INFO ] Starting window manager for display :11
 [INFO ] Starting the xrdp channel server for display :11
 [DEBUG] The user session on display 11 did not request a specific window manager
 [INFO ] Session in progress on display :11. Waiting until the window manager (pid 692537) exits to end the session
 [DEBUG] Calling exec (excutable: /usr/sbin/xrdp-chansrv, arguments: /usr/sbin/xrdp-chansrv)
 [DEBUG] The user home directory window manager configuration is enabled but window manager program does not exist: /root/startwm.sh
 [DEBUG] Closed socket 9 (AF_UNIX)
 [INFO ] Using the default window manager on display 11: /usr/libexec/xrdp/startwm-bash.sh
 [DEBUG] Calling exec (executable: /usr/libexec/xrdp/startwm-bash.sh, arguments: /usr/libexec/xrdp/startwm-bash.sh )
 [INFO ] Window manager (pid 692537, display 11) finished normally in 1 secs
 [WARN ] Window manager (pid 692537, display 11) exited quickly (1 secs). This could indicate a window manager config problem
 [INFO ] Terminating X server (pid 692498) on display :11
 [INFO ] Terminating the xrdp channel server (pid 692538) on display :11
 [INFO ] X server pid 692498 on display :11 finished
 [INFO ] xrdp channel server pid 692538 on display :11 finished
 [DEBUG] cleanup_sockets: deleting /run/xrdp/0/xrdp_chansrv_audio_out_socket_11
 [DEBUG] cleanup_sockets: deleting /run/xrdp/0/xrdp_chansrv_audio_in_socket_11
 [DEBUG] cleanup_sockets: deleting /run/xrdp/0/xrdpapi_11
 [INFO ] Session on display 11 has finished.
 [DEBUG] Closed socket 15 (AF_UNIX)
 [DEBUG] Closed socket 14 (AF_UNIX)
 ```

下記の行が何か問題があったことを物語っているがDEBUGまで出力してもエラーの原因が特定できるような内容が特定できなかった。

 [WARN ] Window manager (pid 692537, display 11) exited quickly (1 secs). This could indicate a window manager config problem


# 解決方法

linuxのサーバをrun level 3で起動する。

```
# systemctl set-default multi-user.target
# init 3
```

これでwindows10からrdpでログインできるようになった。