Debian 9 Stretch Linux 上的 VNC 服务器/客户端设置
客观的
目标是在 Debian 9 Stretch Linux 上配置基本的客户端/服务器 VNC 设置
操作系统和软件版本
操作系统: – Debian 9 Stretch Linux
软件: – vnc4server 4.1.1
要求
安装 VNC 服务器和客户端软件包可能需要特权访问权限来访问 Debian 系统。功能齐全且已配置的 X 服务器。
困难
中等的
惯例
# – 要求以root权限直接以root用户身份或使用
sudo
命令执行给定的linux命令$ – 要求以常规非特权用户身份执行给定的 Linux 命令
指示
服务器
VNC服务器安装
让我们开始安装实际的 VNC 服务器包 vnc4server
:
# apt install vnc4server
设置VNC密码
接下来,我们将为用户设置一个 VNC 密码,该密码最终将从远程客户端创建 VNC 连接。使用 su
以您的用户身份登录并设置新密码。在下面的示例中,我们将为 linuxconfig
用户设置一个新的 vnc 密码:
# su linuxconfig
$ vncpasswd
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
创建x启动脚本
根据您的系统配置,VNC 可能会启动您的默认窗口管理器。此行为可以通过 ~/.vnc/xstartup
脚本覆盖。如果~/.vnc/xstartup
没有退出,请创建它并包含以下内容来启动xterm
:
$ cat ~/.vnc/xstartup
#!/bin/sh
xterm &
启动 VNC 会话
仍以普通用户身份启动新的 VNC 服务器会话。请随意更改以下命令的参数以满足您的需求:
$ vncserver -localhost no -geometry 800x600 -depth 24
New 'linuxconfig:1 (linuxconfig)' desktop at :1 on machine linuxconfig
Starting applications specified in /etc/X11/Xvnc-session
Log file is /home/linuxconfig/.vnc/linuxconfig:1.log
Use xtigervncviewer -SecurityTypes VncAuth,TLSVnc -passwd /home/linuxconfig/.vnc/passwd linuxconfig:1 to connect to the VNC server.
请注意,省略 -localhost no
选项将导致 VNC 服务器仅侦听本地主机的环回接口,因此任何从远程位置进行连接的尝试都将导致错误消息:
unable connect to socket: Connection refused (111)
确认 VNC 会话
确认新的 VNC 会话已正确启动:
$ vncserver -list
TigerVNC server sessions:
X DISPLAY # PROCESS ID
:1 2776
或者,在运行 ss 命令时您还应该看到打开的 VNC 端口:
$ ss -ltp | grep vnc
LISTEN 0 5 *:5901 *:* users:(("Xtigervnc",pid=2776,fd=7))
LISTEN 0 5 :::5901 :::* users:(("Xtigervnc",pid=2776,fd=8))
客户
首先在远程客户端上安装 VNC 查看器包:
# apt install xvnc4viewer
剩下的就是使用 xvncviewer 命令进行连接。根据上面的 vncserver -list
输出,我们的 VNC 会话正在 :1
桌面上侦听。我们将此信息与服务器的 IP 地址结合使用,例如。 10.1.1.124
建立新的远程 VNC 连接:
$ xvncviewer 10.1.1.124:1
TigerVNC Viewer 64-bit v1.7.0
Built on: 2017-04-09 14:55
Copyright (C) 1999-2016 TigerVNC Team and many others (see README.txt)
See http://www.tigervnc.org for information on TigerVNC.
Wed May 31 15:53:28 2017
DecodeManager: Detected 8 CPU core(s)
DecodeManager: Creating 4 decoder thread(s)
CConn: connected to host 10.1.1.124 port 5901
CConnection: Server supports RFB protocol version 3.8
CConnection: Using RFB protocol version 3.8
CConnection: Choosing security type VeNCrypt(19)
CVeNCrypt: Choosing security type VncAuth (2)
Wed May 31 15:53:33 2017
X11PixelBuffer: Using default colormap and visual, TrueColor, depth 24.
CConn: Using pixel format depth 24 (32bpp) little-endian rgb888
CConn: Using Tight encoding
CConn: Enabling continuous updates
附录
重新启动您的 VNC 服务器会话
重新启动 VNC 服务器会话的最简单方法是终止当前会话:
$ vncserver -list
TigerVNC server sessions:
X DISPLAY # PROCESS ID
:1 3081
使用 -kill
选项:
$ vncserver -kill :1
Killing Xtigervnc process ID 3081... success!
并如上所述开始新会话。