背景

前面写了一篇Ubuntu安装VNC远程桌面,但是发现在开机自启上有问题,无法通过非交互式shell启动vnc,后面想到了模拟远程调用的方法去启动,如下:

$ ssh -i /home/ubuntu/vision.pem -o "StrictHostKeyChecking no" ubuntu@127.0.0.1 "sudo su examinee -c 'vncserver -localhost no :1'"

能正常启动,但需要在开机后sleep一段时间,原因是刚开机ssh还没准备好。
还是麻烦,于是想换个远程软件尝试用rdp协议,这里用的是xrdp软件。装下来发现比vnc简单。
这次用的是Ubuntu 20

安装桌面和xrdp

1、更新源

$ sudo apt update

2、安装xrdp

$ sudo apt install xrdp -y

3、安装gnome桌面

$ sudo apt install ubuntu-gnome-desktop

连接

好的完事了,已经可以用windows的远程桌面连接了。打开windows自带的远程连接软件,可以在开始菜单输入mstsc启动。

这里输入账号密码,我用的是ubuntu账号,如果不知道密码,可以用sudo passwd ubuntu来重置。点击连接就可以看到桌面了。

问题


每次连接上去都会有这个弹窗,比较烦,这个提示是要授权桌面颜色管理balabala,具体的解释可以看下面两个链接:

xRDP – The Infamous “Authentication Required to Create Managed Color Device” ExplainedxRDP – How to Fix the Infamous system crash popups in Ubuntu 18.04

解决方案是切换到root用户,在/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

保存即可。

guacamole

官网:https://guacamole.apache.org
这是一个可以在浏览器访问URL来操作服务器的软件,支持很多协议,ssh、rdp、vnc等。本文编辑时最新版本为1.2.0。
1、安装依赖

$ sudo apt install build-essential libcairo2-dev libjpeg-turbo8-dev libpng-dev libtool-bin libossp-uuid-dev libvncserver-dev freerdp2-dev libssh2-1-dev libtelnet-dev libwebsockets-dev libpulse-dev libvorbis-dev libwebp-dev libssl-dev libpango1.0-dev libswscale-dev libavcodec-dev libavutil-dev libavformat-dev -y

2、下载并解压服务端

$ wget http://mirror.cc.columbia.edu/pub/software/apache/guacamole/1.2.0/source/guacamole-server-1.2.0.tar.gz
$ tar -xvf guacamole-server-1.2.0.tar.gz
$ cd guacamole-server-1.2.0

3、编译安装服务端

$ ./configure --with-init-dir=/etc/init.d
$ sudo make
$ sudo make install

4、更新系统缓存

$ sudo ldconfig

5、重新加载systemd,以便它可以guacd在/etc/init.d/目录中找到(Guacamole代理守护程序)服务

$ sudo systemctl daemon-reload

6、启用guacd服务

$ sudo systemctl start guacd

可以用sudo systemctl status guacd查看运行状态。

7、设置开机自启

$ sudo systemctl enable guacd

8、安装tomcat9

$ sudo apt install tomcat9 tomcat9-admin tomcat9-common tomcat9-user -y

9、下载客户端程序并放入tomcat启动

$ wget https://downloads.apache.org/guacamole/1.2.0/binary/guacamole-1.2.0.war
$ sudo mv guacamole-1.2.0.war /var/lib/tomcat9/webapps/guacamole.war
$ sudo systemctl restart tomcat9 guacd

10、创建guacamole配置文件

$ sudo mkdir /etc/guacamole/
$ sudo vim /etc/guacamole/guacamole.properties

将以下内容写入guacamole.properties文件中:

# Hostname and port of guacamole proxy
guacd-hostname: localhost
guacd-port:     4822

# Auth provider class (authenticates user/pass combination, needed if using the provided login screen)
auth-provider: net.sourceforge.guacamole.net.basic.BasicFileAuthenticationProvider
basic-user-mapping: /etc/guacamole/user-mapping.xml

11、配置映射文件

$ sudo vim /etc/guacamole/user-mapping.xml

将以下内容写入/etc/guacamole/user-mapping.xml文件中:

<user-mapping>

    <!-- Per-user authentication and config information -->

    <!-- A user using md5 to hash the password
         amos user and its md5 hashed password below is used to
             login to Guacamole Web UI-->
    <authorize username="visionki" password="password">

		<!-- First authorized connection -->
		<connection name="Unique Name">
			<protocol>rdp</protocol>
			<param name="username">visionki</param>
			<param name="password">password</param>
			<param name="hostname">localhost</param>
			<param name="port">3389</param>
        </connection>
		
    </authorize>

</user-mapping>

authorize
这个是guacamole的登陆账号与密码,支持加密后写入文件,简单起见我就直接明文写入了。
connection
远程协议配置,支持各种远程服务器的协议,我这用的是rdp就配置rdp,其他类型可以到官网查看,子节点的username和password是服务器的账号密码。connection可以配置多个,甚至是其他机器,当只配置了一个的时候访问web界面默认进入这个服务器,若配置了多个则会有个服务器列表选择。
12、重启tomcat和guacd

$ sudo systemctl restart tomcat9 guacd

13、访问guacamole
web链接为

http://ip:8080/guacamole

进入后需要登录,账号密码为user-mapping.xmlauthorize节点的配置。
可以将账号密码放在url免去登录界面:

http://ip:8080/guacamole/#/?username=visionki&password=password

配置桌面图标

如果想把Desktop文件夹里的内容显示在桌面,还需要安装tweak插件,这个插件可以管理一些桌面相关的拓展。

$ sudo apt install gnome-tweak-tool

进入桌面后,打开tweak,选择拓展里的desktop icon即可。

登陆其他用户

1、创建用户

$ sudo useradd -m examinee -d /home/examinee -s /bin/bash

2、修改密码

$ sudo passwd examinee

3、修改guacamole的映射文件文件

$ sudo vim /etc/guacamole/user-mapping.xml

usernamepassword改为对应的用户密码即可。

<connection name="Unique Name">
	<protocol>rdp</protocol>
	<param name="username">examinee</param>
	<param name="password">password</param>
	<param name="hostname">localhost</param>
	<param name="port">3389</param>
</connection>

4、重启tomcat和guacamole

$ sudo systemctl restart tomcat9 guacd