Ubuntu云服安装远程卓面(支持网页连接)

一、安装桌面环境(可选)
Ubuntu系统在server镜像版本中是没有桌面环境,仅支持使用bash控制的。为了让系统能够被链接,需要安装桌面环境。
(若系统已经安装桌面环境请跳过)

1、打开远程连接,使用 sudo su 命令进入root。
2、更新apt源站。(若系统为非大陆区域请跳过)
由于apt站点在国内的访问速度很慢,需要先调整apt至镜像源。此处使用清华源演示。
在终端中使用命令:sudo vi /etc/apt/sources.list 打开vim编辑器,将文件内容全部清空并替换为:

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

保存。

3、同步apt包
将apt列表同步至最新状态。

sudo apt update

方法一 使用tasksel

4、安装tasksel
tasksel是一个常用图形化包管理器。稍后,我们将使用它安装桌面环境。

sudo apt installl tasksel -y

5、安装桌面环境
首先,打开tasksel:

sudo tasksel

效果如图:


使用上下方向键移动,找到“Ubuntu Desktop"并按下空格键选择

接着,依次按下[Tab键]和[Enter]开始安装,并等待安装完成。(此步骤需要很长时间)

方法二 直接apt
直接使用
sudo apt install ubuntu-desktop -y

安装。(此步骤需要很长时间)

二、安装并启动远程桌面服务器(必要)
使用 sudo apt install tigitvncserver -y 安装vnc桌面服务器。vnc可以通过客户端连接,也可通过网页版连接。

安装完成之后,必须使用 sudo reboot 重启

重启后,使用vncserver命令开启远程桌面服务器。

首次启动将请求设定远程桌面密码。

三、连接到远程桌面

  1. 安装网页版连接器
    网页版连接器名:novnc
    Github仓库中下载Novnc并上传至服务器。
    (也可直接使用wget https://github.com/novnc/noVNC/archive/refs/tags/v1.4.0.tar.gz)

由于github在国内访问不稳定,可以尝试使用镜像方法下载。将链接中"github.com"改为"kkgithub.com"即可。

下载完成后,输入tar -zxf noVNC-1.1.0.tar.gz解压即可。

代码中的 noVNC-1.1.0.tar.gz 请自行替换为下载的文件名。

接下来,创建安全连接,保证连接的安全性。执行如下代码,一路回车。

cd ./noVNC/utils/ 
openssl req -new -x509 -days 365 -nodes -out self.pem -keyout self.pem

最后,执行如下命令启动远程连接。

sudo ./novnc_proxy --vnc localhost:5901

网页服务器将在6080端口启动。

注:每次重启均需要手动开启vncserver和novnc。运行novnc前请确保已切换至./noVNC/utils/ 目录.