Remote Desktop on CentOS
Introduction
xrdp is a free and open implementation of the Microsoft RDP (Remote Desktop Protocol) server,
which allows operating systems other than
Microsoft Windows
(such as
Linux
and
BSD
), to provide a fully functional RDP-compatible
remote desktop.
It works by connecting the graphics from the X Window system to the client and relaying the controls
from the client back to
X
.
According to the developers, the protocol works with rdesktop, FreeRDP and Microsoft's own
remote desktop client
Preparing for installation
Before installing xrdp make sure that you have epel-release
yum list epel-release
Loaded plugins: fastestmirror, langpacks Determining fastest mirrors * base: mirror.hosthink.net * epel: www.nic.funet.fi * extras: mirror.hosthink.net * updates: mirror.hosthink.net Installed Packages epel-release.noarch
Installed means that I have epel-release installed
If instead of Installed you see Available, install it with the command
sudo yum install epel-release
To use xrdp you first need to install an X server . For example, Gnome or Xfce.
Install Gnome:
sudo yum update
sudo yum install centos-desktop
Install xfce:
sudo yum update
sudo yum install xcentos-desktop
After installing the X server and epel-release you can proceed directly to installing xrdp
Installation
You can check whether xrdp is present by running
yum list xrdp
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager Loading mirror speeds from cached hostfile * base: mirror.hosthink.net * epel: mirrors.dotsrc.org * extras: mirror.hosthink.net * updates: mirror.hosthink.net Available Packages xrdp.x86_64 1:0.9.15-3.el7 epel
Available means that the package is not installed but is available for installation.
In the last line you can see that xrdp.x86_64 is available from the epel repository. That is why epel-release had to be installed first
xrdp can be installed with the command
sudo yum install xrdp
Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: ftp.funet.fi * epel: mirror.cspacehostings.com * extras: ftp.funet.fi * updates: ftp.funet.fi Resolving Dependencies --> Running transaction check ---> Package xrdp.x86_64 1:0.9.15-3.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ====================================================================================================================================================================== Package Arch Version Repository Size ====================================================================================================================================================================== Installing: xrdp x86_64 1:0.9.15-3.el7 epel 434 k Transaction Summary ====================================================================================================================================================================== Install 1 Package Total download size: 434 k Installed size: 2.1 M Is this ok [y/d/N]:
y
Pay attention to Dependencies Resolved, if tigervnc is not mentioned there, then I recommend installing tigervnc-server yourself.
sudo yum install tigervnc-server
As an option, when installing xrdp, Dependencies Resolved may contain tigervnc-license and tigervnc-server-minimal. This means tigervnc was not forgotten.
If you did not pay attention to the installation logs, you can check what was actually installed during the last use of yum install by simply running
yum history info
If you need to remove everything that was just installed, run
yum history undo 7
Configuration after installation
After installation the contents of the xrdp directory look approximately like this
ls /etc/xrdp
cert.pem km-00000407.ini km-0000040b.ini km-00000411.ini km-00000415.ini km-0000041d.ini km-0000080a.ini km-00000816.ini km-19360409.ini rsakeys.ini xrdp_keyboard.ini key.pem km-00000409.ini km-0000040c.ini km-00000412.ini km-00000416.ini km-00000807.ini km-0000080c.ini km-0000100c.ini openssl.conf sesman.ini km-00000406.ini km-0000040a.ini km-00000410.ini km-00000414.ini km-00000419.ini km-00000809.ini km-00000813.ini km-00010409.ini pulse xrdp.ini
Check the operating mode of SELinux with the command
getenforce
Enforcing
We will not change Enforcing to Permissive and even less to Disabled, but will try to configure everything in this mode.
cd /usr/sbin/
ls -Z xrdp*
-rwxr-xr-x. root root system_u:object_r:bin_t:s0 xrdp -rwxr-xr-x. root root system_u:object_r:bin_t:s0 xrdp-chansrv -rwxr-xr-x. root root system_u:object_r:bin_t:s0 xrdp-sesman
You may also have xrdp-sessvc
If xrdp and xrdp-sesman (Session Manager) have the type unconfined_exec_t you may have to
change it to bin_t manually; this can be done with the command
chcon -t bin_t xrdp xrdp-sesman
Configuring startwm.
The script
startwm.sh
may be located either in /etc/xrdp or in /usr/libexec/xrdp
ls /usr/libexec/xrdp
reconnectwm.sh startwm-bash.sh startwm.sh
An example of the file startwm.sh and modification options can be found in the article startwm
Starting xrdp
systemctl start xrdp
systemctl enable xrdp
Check the status
Check whether port 3389 is listening
netstat -ltn | grep 3389
tcp 0 0 0.0.0.0:3389 0.0.0.0:* LISTEN
Check the xrdp status
sudo systemctl status -l xrdp
-l prints sentences to the end
If everything works, you will see something like:
● xrdp.service - xrdp daemon Loaded: loaded (/lib/systemd/system/xrdp.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2021-01-19 15:21:51 EET; 5min ago Docs: man:xrdp(8) man:xrdp.ini(5) Main PID: 188751 (xrdp) Tasks: 1 (limit: 38009) Memory: 1.9M CGroup: /system.slice/xrdp.service └─188751 /usr/sbin/xrdp Jan 17 15:21:50 andrei xrdp[188750]: (188750)(139708266788672)[INFO ] address [0.0.0.0] port [3389] mode 1 Jan 17 15:21:50 andrei xrdp[188750]: (188750)(139708266788672)[INFO ] listening to port 3389 on 0.0.0.0 Jan 17 15:21:50 andrei xrdp[188750]: (188750)(139708266788672)[INFO ] xrdp_listen_pp done Jan 17 15:21:50 andrei xrdp[188750]: (188750)(139708266788672)[DEBUG] Closed socket 7 (AF_INET6 :: port 3389) Jan 17 15:21:50 andrei systemd[1]: xrdp.service: Can't open PID file /run/xrdp/xrdp.pid (yet?) after start: Operation > Jan 17 15:21:51 andrei systemd[1]: Started xrdp daemon. Jan 17 15:21:52 andrei xrdp[188751]: (188751)(139708266788672)[INFO ] starting xrdp with pid 188751 Jan 17 15:21:52 andrei xrdp[188751]: (188751)(139708266788672)[INFO ] address [0.0.0.0] port [3389] mode 1 Jan 17 15:21:52 andrei xrdp[188751]: (188751)(139708266788672)[INFO ] listening to port 3389 on 0.0.0.0 Jan 17 15:21:52 andrei xrdp[188751]: (188751)(139708266788672)[INFO ] xrdp_listen_pp done
Restarting xrdp
sudo systemctl restart xrdp
Clients
Remmina
sudo yum install remmina
Troubleshooting
If you did everything according to the instructions, but the connection does not work, and when you check the status you get something like
● xrdp.service - xrdp daemon Loaded: loaded (/usr/lib/systemd/system/xrdp.service; disabled; vendor preset: disabled) Active: failed (Result: exit-code) since Sun 2021-04-18 22:39:44 EEST; 12h ago Docs: man:xrdp(8) man:xrdp.ini(5) Process: 11923 ExecStart=/usr/sbin/xrdp $XRDP_OPTIONS --nodaemon (code=exited, status=1/FAILURE) Main PID: 11923 (code=exited, status=1/FAILURE) Apr 18 22:39:44 localhost.localdomain xrdp[11923]: [ERROR] trans_listen_addre... Apr 18 22:39:44 localhost.localdomain xrdp[11923]: [ERROR] xrdp_listen_main_l... Apr 18 22:39:44 localhost.localdomain xrdp[11923]: logging configuration: Apr 18 22:39:44 localhost.localdomain xrdp[11923]: LogFile: /var/log/xr... Apr 18 22:39:44 localhost.localdomain xrdp[11923]: LogLevel: [INFO ] Apr 18 22:39:44 localhost.localdomain xrdp[11923]: ConsoleLevel: <disabled> Apr 18 22:39:44 localhost.localdomain xrdp[11923]: SyslogLevel: [INFO ] Apr 18 22:39:44 localhost.localdomain systemd[1]: xrdp.service: main process ... Apr 18 22:39:44 localhost.localdomain systemd[1]: Unit xrdp.service entered f... Apr 18 22:39:44 localhost.localdomain systemd[1]: xrdp.service failed. Hint: Some lines were ellipsized, use -l to show in full.
● xrdp.service - xrdp daemon Loaded: loaded (/usr/lib/systemd/system/xrdp.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Thu 2021-04-15 12:06:37 EEST; 2min 57s ago Docs: man:xrdp(8) man:xrdp.ini(5) Main PID: 5017 (code=exited, status=1/FAILURE) Apr 15 12:06:37 localhost.localdomain xrdp[5017]: [ERROR] trans_listen_address failed Apr 15 12:06:37 localhost.localdomain xrdp[5017]: [ERROR] xrdp_listen_main_loop: xrdp_listen_get_port failed Apr 15 12:06:37 localhost.localdomain xrdp[5017]: logging configuration: Apr 15 12:06:37 localhost.localdomain xrdp[5017]: LogFile: /var/log/xrdp.log Apr 15 12:06:37 localhost.localdomain xrdp[5017]: LogLevel: [INFO ] Apr 15 12:06:37 localhost.localdomain xrdp[5017]: ConsoleLevel: <disabled> Apr 15 12:06:37 localhost.localdomain xrdp[5017]: SyslogLevel: [INFO ] Apr 15 12:06:37 localhost.localdomain systemd[1]: xrdp.service: main process exited, code=exited, status=1/FAILURE Apr 15 12:06:37 localhost.localdomain systemd[1]: Unit xrdp.service entered failed state. Apr 15 12:06:37 localhost.localdomain systemd[1]: xrdp.service failed.
If you have not done it yet, try installing tigervnc-server (the VNC port is probably involved in the connection).
sudo yum install tigervnc-server
If it did not help right away, restart everything you can. Perhaps the xrdp update should be checked
Article author: Andrei Olegovich