【v3】通过开源软件 XRDP 实现堡垒机远程 Linux(Ubuntu) 远程桌面


飞致云 发布于 2024-10-17 / 39 阅读 / 0 评论 /
概述 当前越来越多的企业都有使用 Linux 系统桌面的场景,本篇文章分别介绍了 XRDP 在 Ubuntu 22.04, 20.04.4 和 18.04.5 的安装方式,以及如何通过配置 XRDP 服务,实现 JumpServer 远程登陆 Ubuntu 桌面。 实现前 检查是否安装图形化工具 r

概述

当前越来越多的企业都有使用 Linux 系统桌面的场景,本篇文章分别介绍了 XRDP 在 Ubuntu 22.04, 20.04.4 和 18.04.5 的安装方式,以及如何通过配置 XRDP 服务,实现 JumpServer 远程登陆 Ubuntu 桌面。

实现前

检查是否安装图形化工具

root@jinli:~# dpkg -l | grep ubuntu-desktop
ii  ubuntu-desktop                             1.450.2                              amd64        The Ubuntu desktop system
ii  ubuntu-desktop-minimal                     1.450.2                              amd64        The Ubuntu desktop minimal system

ubuntu 默认是安装了图形化工具的,环境如果没有安装的话,可以安装一些步骤搭建 GNOME 桌面环境

安装图形化

sudo apt update
sudo apt install ubuntu-desktop

设置默认开启图形化

sudo systemctl set-default graphical.target
reboot

实现方案

一、安装并启动 xrdp

1.1 安装 xrdp

  Ubuntu 的安装源里包含 xrdp,可以直接安装。

1 Ubuntu 22.04.1 安装方式

#更新软件包列表:
sudo apt update

#安装xrdp:
sudo apt install xrdp

#如果你正在使用GNOME桌面环境,可能需要安装一个兼容的会话管理器:
sudo apt install xorgxrdp

#安装后,查看当前xrdp版本:
xrdp -v
xrdp 0.9.17

2 Ubuntu 20.04.4 安装方式

# 检查可安装程序
sudo apt list | grep xrdp
xorgxrdp/focal,now 1:0.2.12-1 amd64
xrdp/focal,now 0.9.12-1 amd64
 
# 安装
sudo apt install xrdp -y
 
# 当前版本为 0.9.12
xrdp -v
xrdp 0.9.12

3 Ubuntu 18.04.5 安装方式

# 直接安装 xrdp 会导致远程后蓝屏,需要配合其他组件一起安装
# 如果已经安装过 xrdp 和 tightvncserver 需先卸载,然后重启系统
# 如果安装报错:E: Unable to locate package xxx,执行 sudo apt-get update 后重试
sudo apt-get purge xrdp -y
sudo apt-get purge tightvncserver -y
sudo reboot
 
# 安装
sudo apt-get install xserver-xorg-core -y
sudo apt-get install xserver-xorg-input-all -y
sudo apt-get install xrdp -y
sudo apt-get install xorgxrdp -y
 
# 当前版本为 0.9.8
xrdp -v
xrdp 0.9.8

1.2 启动 xrdp

配置文件是 /etc/xrdp/xrdp.ini 一般不需要修改,日志输出在 /var/log/xrdp.log 和 /var/log/xrdp-sesman.log。

# 默认情况下,xrdp 使用/etc/ssl/private/ssl-cert-snakeoil.key
# 它仅仅对 ssl-cert 用户组成员可读,所以需要运行下面的命令,将 xrdp 用户添加到这个用户组
sudo adduser xrdp ssl-cert
 
# 启动
sudo systemctl start xrdp
 
# 设置开机自启动
sudo systemctl enable xrdp
 
# 检查监听端口 
sudo ss -nlpt | grep 3389
LISTEN    0         2        *:3389     *:*        users:(("xrdp",pid=861,fd=11))

二、mstsc 连接验证

  安装好以后可以使用 windows 自带的 mstsc 连接测试。
  在开始菜单打开运行,输入 mstsc 点击确定。

配置防火墙开放 3389 端口。

sudo ufw allow 3389/tcp

Seesion 选择 Xorg 模式

等待连接成功

三、JumpServer 配置远程连接

3.1 资产和授权配置

依次点击---资产管理---资产列表---创建,创建资产时注意要有 rdp 的协议。

添加资产账号

进行资产授权

权限管理---资产授权----创建

3.2 登陆

1 使用 Web GUI 方式登陆

连接的时候选择 RDP 客户端连接

测试下来 web gui 方式连接的可以进行监控和录像回放

注意:razor组件客户端连接方式,无法监控和录像回放

四、解决已知问题

4.1连接黑屏问题

修改配置文件

# 修改 /etc/xrdp/startwm.sh 文件,在下图的位置加入这两行
unset DBUS_SESSION_BUS_ADDRESS
unset XDG_RUNTIME_DIR
 
# 重启生效
sudo systemctl restart xrdp

需要注意一下添加的位置

检查用户创建是否有问题,有的用户创建时没有家目录导致连接黑屏

sudo usermod -d /home/username username
chown username:username username

4.2 连接认证失败,root登录问题

第一次远程可以连接,后面选程连接会失败,需要做一些配置调整

修改 gdm 配置

vim /etc/pam.d/gdm-autologin
#注释掉行 "auth requied pam_succeed_if.so user != root quiet success"

vim /etc/pam.d/gdm-password
#注释掉行 "auth requied pam_succeed_if.so user != root quiet success"

修改 /root/.profile,屏蔽最后一行,并添加一行 tty -s && mesg n || true。

4.3 解决普通用户远程登陆时提示认证的问题

需要授权来创建色彩管理设备 / Authentication is required to create a color managed device
    需要授权来移除色彩管理设备 / Authentication is required to remove a color managed device
    刷新系统软件源需要认证 / Authentication is required to refresh the system repositories

解决方法,创建文件 /etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla 并写入下面内容

[Allow Colord all Users]
Identity=unix-user:*
Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile
ResultAny=no
ResultInactive=no
ResultActive=yes

4.4 解决登陆时还需要再输入一遍密码的问题

图形界面会自动锁屏,登陆时xrdp已经验证了一遍,但锁屏后还会要求再输入一遍密码。解决方式是关闭自动锁屏。
注意!关闭锁屏要在远程的界面操作。



是否对你有帮助?