Raspberry Pi: Remote GUI access to a Linux computer using Tightvnc

转载 2015年05月19日 08:37:07


The command line is a great way to manage a remote Linux computer if you don’t mind typing in commands, but sometimes you need to be able to view a GUI. Short of a very long cable one of the best ways of doing this is using the VNC protocol (Virtual Network Computing).

The following are instructions on how to configure this on the Raspberry Pi (Debian based distribution). It should be similar for any other Debian based distribution (eg. Ubuntu). Some other distributions use different software install tools and possibly different init setup tools.

If this is used in combination with the guide to running the Raspberry Pi headless with Debian Linux then it can be used to setup a Raspberry Pi for remote access without ever needing to connect it to a monitor.

Choosing TightVNC

There are several software projects that support VNC. I have chosen to use TightVNC because it is free open source software (GPL2), provides compression to allow it to work over a slow network (Internet) and is readily available in the software repositories.

Client server model

VNC follows the traditional client sever model. The server software runs on the host to be accessed, and client software runs on the local machine that wishes to control the host. The server and client do not have to be the same (eg. the client can be RealVNC when the server is TightVNC), but some features may only work when the same client and server are used.

Install the TightVNC server software

First refresh the software repository information using

sudo apt-get update

This is particularly important if you have just installed the operating system as the repository information may be incomplete.

Install the server software from the repositories:

sudo apt-get install tightvncserver

Start server and configure a password

The first time you run the server it will prompt you to set a password. This is the password that you use when connecting remotely.


There is no need to create a view only password, unless you have a specific need.

When the server starts it will tell you which virtual desktop has been setup. In this case:

New 'X' desktop is raspberrypi:1

says that it’s virtual desktop 1. You would connect to this using :1 at the end of the IP address in the client, this is the one we will setup to start automatically later.

You can run multiple instances. Each time you start tightvncserver it will use the next available desktop, but in most cases you will just need one.

Adding Tightvnc to the startup

To have Tightvnc startup automatically we need to create a new init file.
below is the code we will be adding, but to make it a little easier you can download the file from this webserver.

# Provides:          tightvncserver
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop tightvncserver

# More details see:
# http://www.penguintutor.com/linux/tightvnc

### Customize this entry
# Set the USER variable to the name of the user to start tightvncserver under
export USER='pi'
### End customization required

eval cd ~$USER

case "$1" in
    su $USER -c '/usr/bin/tightvncserver :1'
    echo "Starting TightVNC server for $USER "
    pkill Xtightvnc
    echo "Tightvncserver stopped"
    echo "Usage: /etc/init.d/tightvncserver {start|stop}"
    exit 1
exit 0

To download use the following commands:

wget http://www.penguintutor.com/otherfiles/tightvncserver-init.txt

sudo mv tightvncserver-init.txt /etc/init.d/tightvncserver

You may need to change the variable on line 16. It is currently set to pi which is the default username on the Raspberry Pi Debian image. Set this to whatever username you want to login to TightVNC as. Do not put root as the user.

Change the file so it is owned by root (not strictly neccessary, but is the standard ownership for init files

sudo chown root:root /etc/init.d/tightvncserver

Make the file executable by running

sudo chmod 755 /etc/init.d/tightvncserver

Add the script to the default runlevels with the command

sudo update-rc.d tightvncserver defaults

TightVNC will now start at startup. I’d recommend you reboot at this point to make sure it’s working, but you can just stop and start if you don’t want to reboot.
You can manually start and stop it using

sudo /etc/init.d/tightvncserver start


sudo /etc/init.d/tightvncserver stop

Note that this is designed for running only one instance of TightVNC on the computer. If you want to be able to start and stop specific instances of TightVNC then you will need to tweak the startup script appropriately.

Installing Tightvnc viewer (VNC client) on a Linux computer

On a Linux computer you can install the viewer with

sudo apt-get install xtightvncviewer 

or if that is not in the repositories try:

sudo apt-get install ssvnc 

This will work with Debian / Ubuntu based distributions only, for other distributions use the normal package manager.

Note that ssvnc - which is the version I installed on my Kubuntu computer is based on tightvnc, but also has the ability to configure the ssh tunnelling (see later) through the GUI.

Login using


(replace with your own IP address as appropriate)

TightVNC viewer running on Linux connected to a Raspberry Pi

Installing Tightvnc view on a Windows computer

To access from Windows or using the Java Client download from TightVNC.com

Securing TightVNC

TightVNC allows anyone that knows the password to login as the user that it’s running under. It also does this without encryption so anyone can snoop in on the session. Fortunately there is a secure solution, which is to tunnel the connection over an ssh (secure shell) login.

First step is to restrict Tightvnc to the local computer only. This is done by adding the option -localhost when starting the tightvncserver. To do this edit line 23 in the /etc/init.d/tightvncserver file to read:

su $USER -c '/usr/bin/tightvncserver -localhost :1'

Then restart the server.

To login using ssh - first login to the host computer using ssh

ssh pi@ -L 5901:localhost:5901

The -L option creates the tunnel, from the current computer (default) port 5901 to the host computer (as localhost) port 5901. Port 5901 is the default port for display 1, 5902 for display 2 etc.

To connect using tightvnc now use the command


Note that your previous terminal will now be logged into the Raspberry Pi so you will need to start a new terminal or tab to run the viewer.

If using Windows then the ssh tunnel can be created from within PuTTY

PuTTY providing a ssh tunnel for vnc from Windows to Linux

Then connect using the vnc client using

You can now use the GUI to run applications on the Raspberry Pi without needing a monitor or keyboard. If you have port forwarding set on your router you can do this over the Internet.

Starting your window manager

The instructions above are sufficient for the Raspberry Pi running Debian. You may however need to make a further configuration change to start your normal window manager / application launcher. If you get a blank screen when connecting edit the file ~/.vnc/xstartup and replace the line /etc/X11/Xsession with one of the following as appropriate.

exec ck-launch-session startlxde    #for an lxde session
exec ck-launch-session gnome-session    #for a gnome-session
exec ck-launch-session openbox-session  #for an openbox desktop
exec ck-launch-session startxfce4   #for an xfce desktop
exec ck-launch-session icewm    #for an icewm desktop
exec ck-launch-session startkde #for a kde desktop

For instance with Ubuntu you would use the entry for gnome, for xubuntu you would use xfce and for kubuntu use kde. The Raspberry Pi uses lxde, but this is started automatically on the Raspberry Pi there is no need to add it to the xstartup file.


From: http://www.penguintutor.com/linux/tightvnc

ubuntu 通过VNC 显示Raspberry PI界面

1、将raspberry连接上路由器,通过以下命令查找路由器网段连接的设备 wiwa@tech:~$ sudo nmap -sP Starting Nmap 7....
  • eibo51
  • eibo51
  • 2016年11月22日 21:11
  • 767

Raspberry Pi 3学习系列——基本使用

  • Kelsey98
  • Kelsey98
  • 2018年01月02日 11:06
  • 284

Raspberry Pi: VNC安装与配置

Server1.下载安装TightVNC Server$ sudo apt-get install tightvncserver 2.开启vncserver$ vncserver 此时会要求设置密码,...
  • IOIO_
  • IOIO_
  • 2017年06月19日 22:44
  • 554

Raspberry Pi: Installing TightVNC

Installing TightVNC on the Raspberry PiSometimes connecting a keyboard, mouse, and monitor to Raspbe...
  • IOIO_
  • IOIO_
  • 2015年05月20日 07:46
  • 617

树莓派2(Raspberry Pi 2 )上的tightvnc多用户端口登陆配置

  • u010940020
  • u010940020
  • 2015年04月26日 18:14
  • 2438

为Raspberry Pi 2编译内核模块

2015-04-21更新:原始的rpi-source项目已经由PeterOGB 接手维护,所以无须再用我下文中提到的我改过的rpi-source脚本,直接用原始的就可以了。其它文中提到的背景知识都仍然...
  • zdf511391565
  • zdf511391565
  • 2015年08月14日 14:40
  • 1177

raspberry pi + git

一、GitHub配置 1、树莓派系统应该内置了git,使用之前用命令$ git可以确认相关信息,如下图所示 如果没有git的相关信息,即git未安装,使用命令$sudo apt-get insta...
  • OunUa
  • OunUa
  • 2017年02月15日 21:21
  • 933

Raspberry pi,一个好玩的派:第五季 无线网卡

Raspberry pi的板子由于成本原因是没有加无线模块的,不想被网线束缚的我们,需要自备USB无线模块。在购买板子时,看见官方推荐EDUP无线网卡,价格还算合适,就直接入手了。...
  • lincyang
  • lincyang
  • 2014年12月08日 21:22
  • 7735

Raspberry Pi B+ 实验

使用Raspberry Pi B+进行实验。
  • LiJiancheng0614
  • LiJiancheng0614
  • 2015年12月01日 10:43
  • 848

【Raspberry Pi 3试用体验】+ 中文显示及输入+百度云传输

树莓派系统显示中文的话,大部分都是一个的小方块,还好我们有非常无私的开源者: sudo apt-get install ttf-wqy-zenhei 复制代码 文泉驿的开...
  • u010873775
  • u010873775
  • 2016年04月22日 21:44
  • 1457
您举报文章:Raspberry Pi: Remote GUI access to a Linux computer using Tightvnc