分享交流
合作共赢!

Ubuntu 18.04 TLS安装和配置VNC

一、简介

VNC是Virtual Network Computing的字母缩写,是一种桌面共享系统或者说协议。可以用来控制和访问远程桌面。一般具有相似功能的程序包有TigerVNC, TightVNC, Vino(Gnome桌面默认使用),x11vnc, krfb(KDE桌面默认使用), vnc4server等。下面示例用来演示如何在ubuntu18.04 TLS系统上安装配置TigerVNC来访问Gnome3桌面。

二、安装配置

相关程序包参考地址:https://www.realvnc.com/en/connect/download/viewer/linux/

安装配置参考:
https://www.cyberciti.biz/faq/install-and-configure-tigervnc-server-on-ubuntu-18-04/
https://computingforgeeks.com/how-to-install-vnc-server-on-ubuntu/

1.安装桌面环境程序包

假如ubuntu系统没有桌面程序,需要先行安装

# apt install ubuntu-gnome-desktop
# systemctl enable gdm
# systemctl start gdm

2.安装tigerVNC及依赖程序包

$ apt install tigervnc-standalone-server tigervnc-xorg-extension tigervnc-viewer

3.设置VNC密码

# vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? y
Password:
Verify:

4.配置VNC文件

在用户所在家目录下创建~/.vnc/xstartup,并写入如下内容:

vi ~/.vnc/xstartup
#!/bin/sh
# Start Gnome 3 Desktop 
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
vncconfig -iconic &
dbus-launch --exit-with-session gnome-session &

5.启动VNC

# vncserver -localhost no

VNC命令使用参考:

# vncserver --help
usage:
vncserver -help|-h|-? This help message. Further help in tigervncserver(1).

vncserver [:<number>] X11 display for VNC server
[-dry-run] Take no real action
[-verbose] Be more verbose
[-useold] Only start VNC server if not already running
[-name <desktop-name>] VNC desktop name
[-depth <depth>] Desktop bit depth (8|16|24|32)
[-pixelformat X11 server pixel format
rgb888|rgb565|rgb332 blue color channel encoded in lower bits
|bgr888|bgr565|bgr233] red color channel encoded in lower bits
[-geometry <dim>] Desktop geometry in <width>x<height>
[-xdisplaydefaults] Get geometry and pixelformat from running X
[-wmDecoration <dim>] Shrink geometry from xdisplaydefaults by dim
[-localhost yes|no] Only accept VNC connections from localhost
[-httpPort port] Port of internal http server
[-baseHttpPort port] Calculate http port from base port + display nr
[-fg] No daemonization and
kill the VNC server after its X session has terminated
[-autokill] Kill the VNC server after its X session has terminated
[-noxstartup] Do not run the Xvnc-session script after launching Xtigervnc
[-xstartup] Specify the script to start after launching Xtigervnc
[-fp fontpath] Colon separated list of font locations
[-cleanstale] Do not choke on a stale lockfile
[-SecurityTypes] Comma list of security types to offer (None, VncAuth,
Plain, TLSNone, TLSVnc, TLSPlain, X509None, X509Vnc,
X509Plain). On default, offer only VncAuth.
[-PlainUsers] In case of security types Plain, TLSPlain, and X509Plain,
this options specifies the list of authorized users.
[-PAMService] In case of security types Plain, TLSPlain, and X509Plain,
this options specifies the service name for PAM password
validation (default vnc if present otherwise tigervnc).
[-PasswordFile] Password file for security types VncAuth, TLSVnc, and X509Vnc.
The default password file is ~/.vnc/passwd
[-passwd] Alias for PasswordFile
[-rfbauth] Alias for PasswordFile
[-X509Key] Path to the key of the X509 certificate in PEM format. This
is used by the security types X509None, X509Vnc, and X509Plain.
[-X509Cert] Path to the X509 certificate in PEM format. This is used by
the security types X509None, X509Vnc, and X509Plain.
<X11-options ...> Further options for Xtigervnc(1)
[-- sessiontype] Arguments for the VNC startup script Xvnc-session

vncserver -kill Kill a VNC server
[:<number>|:*] VNC server to kill, * for all
[-dry-run] Take no real action
[-verbose] Be more verbose
[-clean] Also clean log files of VNC session

vncserver -list List VNC server sessions
[:<number>|:*] VNC server to list, * for all
[-cleanstale] Do not list stale VNC server sessions

此时查看主机所监听端口显示如下:

# netstat -tanlp | grep vnc
tcp 0 0 0.0.0.0:5901 0.0.0.0:* LISTEN 57275/Xtigervnc
tcp6 0 0 :::5901 :::* LISTEN 57275/Xtigervnc

常用命令:

结束运行中的vnc:

vncserver -list (查看所有运行的vnc进程)

vncserver -kill :1 (结束编号为1的vnc进程)

vncserver -kill :* (结束所有vnc进程)

6.安全性介绍

VNC是一种明文的、不安全的网络协议。要使通信安全,必须使用VNC服务器和客户机之间的SSH隧道加密服务器-客户机连接。在Linux或Unix桌面中,输入以下ssh命令设置ssh隧道:

# ssh user@remote-server -L 5901:127.0.0.1:5901

这样就可以通过ssh命令通过vnc连接远程主机了,如下所示是我的测试结果。

赞(0) 打赏
未经允许不得转载:琼杰笔记 » Ubuntu 18.04 TLS安装和配置VNC

评论 抢沙发

评论前必须登录!

 

分享交流,合作共赢!

联系我们加入QQ群

觉得文章有用就打赏一下文章作者

非常感谢你的打赏,我们将继续给力更多优质内容,让我们一起创建更加美好的网络世界!

支付宝扫一扫打赏

微信扫一扫打赏