注意:这篇文章上次更新于380天前,文章内容可能已经过时。
This article was last updated380 days ago, the content may be outdated.
本文介绍了一种在 Ubuntu 环境下搭建远程桌面服务的方法。
主要环境:
其他环境和工具:
- 1panel
- openresty (nginx)
- supervisor (or systemd)
安装和配置 VNC 服务端
- 安装 TigerVNC
在 sourceforge 上下载 TigerVNC 的程序包。
https://sourceforge.net/projects/tigervnc/files/stable/1.13.1/

下载完成后,解压到指定目录。
我这里放在了 /opt/ 目录下。
解压后的目录结构如下:
1 | wgxls@server:/opt$ tree tigervnc-1.13.0.x86_64/ |
- 配置 x0vncserver
首先给 VNC 服务生成密码。
1 | # 切换到 tigerVNC 的 bin 目录 |
这里将会提示输入两次密码,这个密码用于远程登录的认证服务。
然后查看当前的显示器序号。
1 | printenv DISPLAY |
这里显示的是 :0,表示当前显示器的序号是 0。
然后启动 x0vncserver 服务。
我这里使用的 x0vncserver,可以直接连接到当前桌面环境。
在效果上就和 Windows 的远程桌面服务,向日葵等工具类似。
如果使用 Xvnc,会新开一个桌面环境,远程访问的效果和本地不同。
1 | # 切换到 tigerVNC 的 bin 目录 |
简单解释一下这三个参数:
-display :0:指定显示器序号。-passwordfile ~/.vnc/passwd:指定密码文件。-NeverShared:表示不共享,只允许一个用户连接。
全部支持的参数信息可以查看帮助文档。
⚠️ TigerVNC 的 vncpasswd 命令进行了更新,现在
passwd文件会生成在$HOME/.config/tigervnc/passwd,注意更新相关命令。
参考:https://tigervnc.org/doc/vncpasswd.html
- 配置桌面环境
根据我的实验,如果使用 Wayland 桌面环境,x0vncserver 连上后就只能看到一个黑屏。
所以首先关闭 Wayland。
同时,为了能让电脑在一开机的时候就能够自动启动 x0vncserver 服务,我们需要开机桌面的自动登录,为了创建一个 X 会话。
1 | # 编辑 /etc/gdm3/custom.conf 文件 |
修改完之后,重启电脑。
安装和配置 noVNC
- 下载 noVNC
我这里在 /opt/ 目录下存放 noVNC 的程序包。
1 | cd /opt |
- 配置 noVNC
1 | cd /opt/noVNC |
第一次执行这个命令的时候,会自动下载 websockify。
至此,核心部分的配置已经完成。
配置守护进程和反向代理
因为我的服务器上安装了 1panel,1panel 提供了图形界面去管理 supervisor 守护进程。
所以我这里使用 supervisor 来管理 noVNC 和 x0vncserver 服务。
登录 1panel 后点击 工具箱 -> 守护进程
如果服务器没有安装 supervisor,可以按照提示进行安装。
安装完成 supervisor 后, 在 1panel 的 守护进程 页面,点击初始化,然后点击创建守护进程。
首先添加 x0vncserver 的守护进程, 下图是我的例子,可以根据自己的实际情况进行配置。

启动命令我填写的是:/opt/tigervnc-1.13.0.x86_64/usr/bin/x0vncserver -display :0 -passwordfile /home/wgxls/.vnc/passwd -NeverShared
然后添加 noVNC 的守护进程,如图所示:

最后,添加网站并配置反向代理,这一步是常规操作,这里不再赘述。
我这里的反向代理配置如下:
1 | location ^~ / { |
如果你的网站域名是 example.com,那么你可以通过 https://example.com/vnc.html 访问 noVNC。

设置 Dummy 显示器
如果你需要在没有物理显示器的服务器上使用 x0vncserver,可以设置一个 Dummy 显示器。
- 安装 Dummy 驱动
1 | sudo apt install xserver-xorg-video-dummy |
- 创建配置文件
1 | sudo vim /etc/X11/xorg.conf.d/10-dummy.conf |
在文件中添加以下内容:
1 | Section "Device" |
- 重启 X 服务器或重启服务器
1 | sudo systemctl restart gdm3 |
然后就可以远程访问了。
This article describes a method to set up a remote desktop service in an Ubuntu environment.
Main environment:
Other environment and tools:
- 1panel
- openresty (nginx)
- supervisor (or systemd)
Install & configure the VNC server
- Install TigerVNC
Download the TigerVNC package from sourceforge.
https://sourceforge.net/projects/tigervnc/files/stable/1.13.1/

After downloading, extract it to a directory of your choice.
I put mine in /opt/.
The extracted directory structure:
1 | wgxls@server:/opt$ tree tigervnc-1.13.0.x86_64/ |
- Configure x0vncserver
First, generate a password for the VNC service.
1 | # Switch to tigerVNC's bin directory |
It will prompt you to enter the password twice. This password is used for remote login authentication.
Then check the current display number.
1 | printenv DISPLAY |
This shows :0, meaning the current display number is 0.
Then start the x0vncserver service.
I use x0vncserver here, which connects directly to the current desktop environment.
In terms of effect, it’s similar to Windows Remote Desktop, Sunflower (Xiangrikui), and similar tools.
If you use Xvnc instead, it creates a brand new desktop environment, so the remote experience differs from the local one.
1 | # Switch to tigerVNC's bin directory |
A quick explanation of these three parameters:
-display :0: specifies the display number.-passwordfile ~/.vnc/passwd: specifies the password file.-NeverShared: no sharing — only one user can connect at a time.
See the help docs for all supported parameters.
⚠️ TigerVNC’s vncpasswd command was updated; the
passwdfile is now generated in$HOME/.config/tigervnc/passwd. Update the relevant commands accordingly.
Reference: https://tigervnc.org/doc/vncpasswd.html
- Configure the desktop environment
From my experiments, if you use the Wayland desktop environment, x0vncserver only shows a black screen after connecting.
So first, disable Wayland.
Also, to have x0vncserver start automatically at boot, we need auto-login at the desktop level to create an X session.
1 | # Edit the /etc/gdm3/custom.conf file |
After the changes, reboot the computer.
Install & configure noVNC
- Download noVNC
I put the noVNC package in /opt/.
1 | cd /opt |
- Configure noVNC
1 | cd /opt/noVNC |
The first time you run this command, websockify will be downloaded automatically.
At this point, the core configuration is done.
Configure the daemon and reverse proxy
Since my server has 1panel installed, and 1panel provides a GUI to manage supervisor daemons,
I use supervisor to manage the noVNC and x0vncserver services.
After logging into 1panel, click Toolbox -> Daemons.
If supervisor isn’t installed on the server, follow the prompts to install it.
Once supervisor is installed, on the 1panel Daemons page, click initialize, then click create daemon.
First add the x0vncserver daemon. The image below is my example; configure it according to your actual situation.

The start command I filled in: /opt/tigervnc-1.13.0.x86_64/usr/bin/x0vncserver -display :0 -passwordfile /home/wgxls/.vnc/passwd -NeverShared
Then add the noVNC daemon, as shown:

Finally, add a website and configure the reverse proxy — this is a routine operation, so I won’t go into detail here.
My reverse proxy configuration:
1 | location ^~ / { |
If your site domain is example.com, you can access noVNC via https://example.com/vnc.html.

Set up a Dummy display
If you need to use x0vncserver on a server without a physical monitor, you can set up a Dummy display.
- Install the Dummy driver
1 | sudo apt install xserver-xorg-video-dummy |
- Create the config file
1 | sudo vim /etc/X11/xorg.conf.d/10-dummy.conf |
Add the following to the file:
1 | Section "Device" |
- Restart the X server or reboot the server
1 | sudo systemctl restart gdm3 |
And then you can access it remotely.


