Objective
The objective is to configure a basic client/server VNC setup on Debian 9 Stretch LinuxOperating System and Software Versions
- Operating System: - Debian 9 Stretch Linux
- Software: - vnc4server 4.1.1
Requirements
Privileged access to access do your Debian system may be required to install VNC server and client packages. Fully functional and configured X server.Difficulty
MEDIUMConventions
- # - requires given linux commands to be executed with root privileges either directly as a root user or by use of
sudo
command - $ - requires given linux commands to be executed as a regular non-privileged user
Instructions
Server
VNC server Installation
Let's begin by installation the actual VNC server packagevnc4server
: # apt install vnc4server
Set VNC password
Next, we are going to set a VNC password for a user which will eventually create a VNC connection from a remote client. Login as you user usingsu
and set a new password. In the example below we will set a new vnc password for linuxconfig
user: # su linuxconfig $ vncpasswd Password: Verify: Would you like to enter a view-only password (y/n)? n
Create xstartup script
Depending on your system configuration VNC might start your default windows manager. This behavior can be overridden by~/.vnc/xstartup
script. If the ~/.vnc/xstartup
does not exits create it and inlcude the following content to start xterm
: $ cat ~/.vnc/xstartup #!/bin/sh xterm &
Subscribe to RSS and NEWSLETTER and receive latest Linux news, jobs, career advice and tutorials.
Start VNC session
Still as a regular user start a new VNC server session. Feel free to change below command's parameters to suit your needs:$ 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.Note, omitting
-localhost no
option will cause VNC server to listen only on a localhost's loopback interface, hence any attempt to connect from a remote location will result in error message: unable connect to socket: Connection refused (111)
Confirm VNC Session
Confirm that new VNC session started correctly:$ vncserver -list TigerVNC server sessions: X DISPLAY # PROCESS ID :1 2776Alternatively, you should also see open VNC ports when running
ss
command: $ ss -ltp | grep vnc LISTEN 0 5 *:5901 *:* users:(("Xtigervnc",pid=2776,fd=7)) LISTEN 0 5 :::5901 :::* users:(("Xtigervnc",pid=2776,fd=8))
Client
On your remote client first install VNC viewer package:# apt install xvnc4viewerAll what remains is to connect using
xvncviewer
command. Based on the above vncserver -list
output our VNC session is listening on :1
desktop. We use this information with a combination of server's IP address eg. 10.1.1.124
to establish a new remote VNC connection: $ 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

Appendix
Restart your VNC server session
The easiest way to restart your VNC server session is to kill the current session:$ vncserver -list TigerVNC server sessions: X DISPLAY # PROCESS ID :1 3081with
-kill
option: $ vncserver -kill :1 Killing Xtigervnc process ID 3081... success!and start new session as described above.