Ubuntu 20.04安装VNC-Server

822 阅读1分钟

参考文档

###
https://blog.csdn.net/qq_42164483/article/details/126447799

1、 Ubuntu 20 配置 apt 源

vi /etc/apt/sources.list

替换为下面内容

deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

执行

apt-get update

2、先决条件

安装 gnome 桌面

sudo apt-get install gnome-panel
apt-get install x-window-system-core
apt-get install ubuntu-desktop
apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal

3、安装

## 
apt update

##
apt install tightvncserver
 

4、远程连接端口开启

  vncserver :1
root@afgttsmcxyhpkpr9:~# vncserver :1

New 'afgttsmcxyhpkpr9:1 (root)' desktop at :1 on machine afgttsmcxyhpkpr9

Starting applications specified in /etc/X11/Xvnc-session
Log file is /root/.vnc/afgttsmcxyhpkpr9:1.log

Use xtigervncviewer -SecurityTypes VncAuth -passwd /root/.vnc/passwd :1 to connect to the VNC server.

通过ss 查看端口占用情况如下:

ss -antlp|grep 5901

结果如下:

LISTEN    0         5                127.0.0.1:5901             0.0.0.0:*        users:(("Xtigervnc",pid=268915,fd=7))                         
LISTEN    0         5                    [::1]:5901                [::]:*        users:(("Xtigervnc",pid=268915,fd=8)) 

使用nc 进行连接测试

image.png

发现只能使用 127.0.0.1 5901 可以建立vnc 连接

5、使用docker 安装

docker pull vncserver/lubuntu

docker run -d --hostname lubuntu --name lubuntu --restart always -p 5901:5901 -e TZ=Asia/Jakarta vncserver/lubuntu

default vnc

host: 127.0.0.1:5901
username: developer
password: vncpasswd

6. 常见问题

提示:Too many authentication failures

若出现如下错误提示,可先关闭端口,再开启即可。

vncserver -kill :1
vncserver :1