Ubuntu20.04之VNC的安装与使用

您所在的位置:网站首页 开启vnc桌面 Ubuntu20.04之VNC的安装与使用

Ubuntu20.04之VNC的安装与使用

2024-01-20 09:39| 来源: 网络整理| 查看: 265

本教程适用于Ubuntu20.04及以下版本,Ubuntu22.04版本或有出入 更多更新的文章详见我的个人博客:【前往】

文章目录 1.安装图形桌面1.1选择安装gnome桌面1.2选择安装xface桌面 2.安装VNC-Server3.配置VCN-Server4.连接VNC5.设置VNC-Server为系统服务(可选)

1.安装图形桌面

如果linux系统已经安装了图形桌面可跳过这一步

Ubuntu20.04主流的图形桌面有gnome和xface两种,两种桌面的安装方式我都会写,但这里较推荐gnome桌面

1.1选择安装gnome桌面 sudo apt update #更新软件源 sudo apt install ubuntu-gnome-desktop #安装gnome sudo systemctl start gdm #刚安装Gnome,需要启动GDM服务以初识化桌面 1.2选择安装xface桌面 sudo apt update #更新软件源 sudo apt install xfce4 xfce4-goodies #安装xface

在这里插入图片描述

这个选项选择是否启用显示管理器,选择第一个并Enter

显示管理器是一个程序,使您的 Linux 发行版拥有图形登录功能。它还负责在您使用用户名和密码登录后启动显示服务器和桌面环境

2.安装VNC-Server

主流的vnc软件有RealVNC、TightVNC、x11vnc等

RealVNC是由VNC团队部分成员开发,分为全功能商业版及免费版。TightVNC则强调节省带宽使用。UltraVNC加入了TightVNC的部分程序及加强效能的图形映射驱动程序,并结合Active Directory及NTLM的帐号密码认证,但仅有Windows版本。 Vine Viewer是MacOSX的VNC用户端。这些软件各有所长,例如UltraVNC支持文件传输以及全屏模式。而这些软件间大多遵循基本的VNC协议,因此大多可互通使用。

需要说明的是VNC分为Server(服务端,用于提供图像数据)和Client (客户端,用于接收图像数据),这里推荐使用TightVNC Server + RealVNC View的组合

sudo apt install tigervnc-standalone-server #在ubuntu上安装tigervnc-server

安装完tigervnc后需要启动一个vncserver来初识化密码

sudo vncserver #启动vnc-server

首次启动需要定义一个6-8位的密码,超8位密码会被自动截断

You will require a password to access your desktops. Password: Verify: Would you like to enter a view-only password (y/n)? n

设置完vncserver的密码后先关闭vncserver做进一步的配置,否则现在连接你的客户端上是一篇空白的

sudo vncserver -kill :*

Tip: 你可以通过下面的命令修改你的vncserver的密码

sudo vncpasswd 3.配置VCN-Server 创建并添加xstartup文件到/etc/vnc/xstartup(这步一定要做) sudo mkdir /etc/vnc #创建VNC目录 sudo nano /etc/vnc/xstartup #创建并编辑xstartup文件 向/etc/vnc/xstartup文件中添加下面的内容(Ctrl+O->Enter->Ctrl+X保存文件) #!/bin/sh test x"$SHELL" = x"" && SHELL=/bin/bash test x"$1" = x"" && set -- default unset SESSION_MANAGER unset DBUS_SESSION_BUS_ADDRESS vncconfig -iconic & "$SHELL" -l Ctrl+X保存文件) #!/bin/sh [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources 设置为可执行文件 sudo chmod a+x ~/.vnc/xstartup 启动VCN-Server sudo vncserver :1 -geometry 1920x1080 -depth 24 -localhost no

注:-localhost no参数一定要有,没有的话可能无法正常连接,其余参数就是分辨率之类的了,可自定义参数

如果输出下面的类似内容则说明服务器端正常运行

New 'bytexd:1 (edxd)' desktop at :1 on machine bytexd Use xtigervncviewer -SecurityTypes VncAuth -passwd /home/edxd/.vnc/passwd :1 to connect to the VNC server. 4.连接VNC

安装VNC View,VNC View就有很多选择了

TigerVNC-Client:前往下载RealVNC-Client:前往下载MobaXterm(推荐):前往下载

连接VNC

大部分的VNC-Client都是只需要Ubuntu的 IP + 端口 + 密码 即可,这里说明一下端口

端口号就是5900+服务器索引,如 vncserver :1指令开启的是第一个服务器,因此第一个服务器的端口就是5901,类推,vncserver :2的端口就是5902

5.设置VNC-Server为系统服务(可选)

为设置vnc开机自启,不用每次都需要输入指令开启,可以将vnc-server的开启指令添加到系统服务中

创建并添加到 /etc/systemd/system/[email protected] 文件中 nano /etc/systemd/system/[email protected]

向文件里面添加以下内容

[Unit] Description=Start TigerVNC server at startup After=syslog.target network.target [Service] Type=simple User=root PAMName=login PIDFile=/home/tom/.vnc/%H:%i.pid ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1 ExecStart=/usr/bin/vncserver -fg -depth 24 -geometry 1920x1080 -localhost no :%i ExecStop=/usr/bin/vncserver -kill :%i [Install] WantedBy=multi-user.target 开机自启vncserver sudo systemctl daemon-reload #加载引导程序 sudo sudo systemctl enable [email protected] # 设置开机自启

输出内容如下:

Created symlink /etc/systemd/system/multi-user.target.wants/[email protected] → /etc/systemd/system/[email protected].

启动服务 sudo sudo systemctl start [email protected] 检查服务状态 sudo sudo systemctl status [email protected]

输出下面内容则服务启动正常:

image-20230717215921211



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3