Raspberry Pi VNC Mirror – simplified

This post describes to setup a VNC Mirror on your Raspberry Pi. You can see any desktop of any machine running VNC on your Raspberry Pi’s connected screen. You may come from these posts: Hardening the Raspberry Pi VNC Mirror and Raspberry Pi – VNC Mirror (Repeater) – Make any computer public anywhere which can be a little bit confusing especially when trying to get both into one project. Here in a few easy and understandable steps


Download the latest Raspbian Image from the Raspberry Pi site. Unpack it and write the IMG file with Win32DiskImager (on Windows) or dd (on Linux or MAC) on your SD Card (make sure you have at least 4GB).

First Start

When you first start your Raspberry Pi with a monitor it runs raspi-config. If it doesn’t you can rerun it with

sudo raspi-config

In this menu select

Enable Boot to Desktop/Scratch


Desktop Log in as user 'pi'...

but say No to reboot, because we want to know the IP address of the raspberry and work via SSH later on. Type


to get your IP address. You may remember it or write it down. Now you can type


to restart the Raspberry Pi. (Please do not unplug the Raspberry Pi instead of rebooting because your filesystem may get corrupted)

Installing and configuring

On next start login to SSH via PuTTY (or similair SSH client) and standard credentials (pi/raspberry) Start a root console with

sudo bash

Company / Proxy settings

If you are in a company or using proxies you need to set them for updates and upgrades of packages (you don’t need this in most home environments)

nano /etc/apt/apt.conf

and enter your proxy:

    Acquire::http::Proxy "http://user:password@proxy1.sysstem.at:8080";

Update, Upgrade and Install packages

After the proxy settings are done start the update of the package information and the upgrade your packages

apt-get update && apt-get upgrade -y

Install packages needed for maintaining and for the VNC mirror itself

apt-get install -y x11vnc vim ssvnc unp htop

Store VNC Passwords

Generate a hidden directory for the VNC password file

mkdir /home/pi/.vnc

Generate a VNC password for X11VNC

x11vnc -storepasswd /home/pi/.vnc/x11vncpasswd

Store the VNC password of the remotemachine (the password you have defined on the remote machine)

x11vnc -storepasswd /home/pi/.vnc/remotevncpasswd

set read permission for the password files

chmod +r /home/pi/.vnc/*



open the following file

vim /home/pi/vncviewer

and copy the following content (more about it’s content you can find here)

# Process check script: The script simply checks if a process is running and if it is not found to be running it will execute it.
# The script loops in preset intervals, hence it is possible to monitor a process continuously.

# Variables
ProcessInstances=`sudo ps aux | grep [s]svncviewer | wc -l`

#VNC Variables
para="-display :$display -viewonly -fullscreen -shared -passwd $passfile -scale $resolution -encoding zrle"

function checkstatus() {
        vncpid=$(pidof ssvncviewer)
        sigign=$(sudo cat /proc/${vncpid}/status | grep SigIgn | awk '{print $2}')

# Logic
while [ $Running -gt 0 ]

        if [ `sudo ps aux | grep [s]svncviewer | wc -l` -gt 0 ]; then
                echo Process already running! Checking the Status.
                if [ $sigign !=  "0000000000000004" ]; then
                        echo SSVNCViewer has not status 4
                        echo Killing SSVNCViewer
                        kill ${vncpid}
                        echo SSVNCViewer status seems to be ok
                echo Process not running! Starting process
                # This is the command that should start the process in question
                $vnc $host $para &

        # How often shall we repeat the check?
        echo Sleeping for $SleepInterval seconds
        sleep $SleepInterval


exit 0

Change the permission for this script to execute

chmod +x /home/pi/vncviewer

VNCViewer Daemon

Make a little Daemon for the vncviewer to start and stop it.

vim /etc/init.d/vncviewerd

enter the following


# Provides: vncviewerd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start or stop Custom VNC Viewer
# Description: Start or stop Custom VNC Viewer
#! /bin/sh
# /etc/init.d/monitor
# Carry out specific functions when asked to by the system

#Start vncviewer
start() {
    echo Starting VNC Viewer
    su pi /home/pi/vncviewer &
#Stop vncviewer
stop() {
    echo Stopping VNC Viewer
    pkill -f vncviewer

### main logic ###
case "$1" in

        echo "Usage: $0 {start|stop|restart|reload}"
        exit 1
exit 0

Make the script executable

chmod +x /etc/init.d/vncviewerd

and register it for autostart

update-rc.d vncviewerd defaults


Create a script for turning on and off your monitor

vim /etc/init.d/monitor

enter the following


# Provides: monitor
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start or stop Monitor
# Description: Start or stop Monitor
#! /bin/sh
# /etc/init.d/monitor
# Carry out specific functions when asked to by the system

#Start Monitor
start() {
    echo Starting Monitor
    # Enable HDMI with preferred mode
    /opt/vc/bin/tvservice -p
    # Change console to enable monitor output
    # not very nice but ok
    sudo chvt 6
    sudo chvt 7
#Stop Monitor
stop() {
    echo Stopping Monitor
    /opt/vc/bin/tvservice -o

### main logic ###
case "$1" in

        echo "Usage: $0 {start|stop|restart|reload}"
        exit 1
exit 0

Make it executable (but do not add it to autostart!)

chmod +x /etc/init.d/monitor

Miscellaneous Monitor settings

Disable monitor standby

vim /etc/kbd/config

search for POWERDOWN_TIME=30 and set it to 0


Restart KBD to activate new settings

sudo /etc/init.d/kbd restart

Disable overscan (it tries shrink the picture a little to fit on older monitors and TVs)

vim /boot/config.txt

remove the sharp (#) from #disable_overscan=1 it should now look like this


Now it’s time to reboot your Raspberry VNC Mirror.


If you have questions or problems left leave them in the comments!

37 thoughts on “Raspberry Pi VNC Mirror – simplified”

  1. Hi, i have one question.. i have done this like your statement….

    everythink works fine. i dind’t do the Monitor settings, because my system works 365 days a yeahr.

    so my problem is , that after 10 min the rasp will be black. like screensaver or something else… did you have any ideas ??

    how i can solve my problem ?

    Thank you

    1. Thank you for your interest in this topic. I forget to add the kbd restart after you have done the settings. I added it to the article

      sudo vim /etc/kbd/config

      #Change to this

      #restart KBD

      sudo /etc/init.d/kbd restart

      1. hi, is it possibel to become in contakt per mail ?!

        i have got another question.

        The system is not stable… my display is freezing sometimes… so… did you have any ideas ?

        Thanks los

  2. Hello, on my raspberry, I have already setup XMBC, and It works fine.
    Can I do the same job as you did ? There is any way to do the same using XBMC?
    Thanks a lot

  3. hello i have followed the manipulation but i have message : Unable to connect ro VNC server : (WSWDL02:590 1). However my VNCServer is running on my remote laptop.
    Could you help me ?

  4. I put in the name of my laptop instead of WSWDL02. However, now I just get the same error with “Unable to connect to VNC server (Laptop_PC:5900)”. Any ideas?

  5. I am using ultraVNC. It is running (I started service) it shows two IP addresses and the name of my laptop. An earlier comment said that we are supposed to use the name of our laptop. Should I be using one of these IP addresses anywhere? Sorry for being so bad at this and thanks again.

  6. I have the same issue with Taoh, my Raspberry Pi cannot connect to the PC, i am using Raspbery pi 2 model B, I think my VNC server on my PC is alright as i wass able to connect my smartphone that running VNC viewer to my VNC server, Please help me, I really need to make this work, my 2 years hardwork of study will be destroyed if i couldnt get my final year project done before 21 next month, please i beg you help me for this issue, I have followed all the step by step guide, please help me

  7. I open the vncviewer file and copy in the content, but I can figure out how to save that file. I tried to run it while it was open, but it can’t find it. There must be a way to save and exit, but I can’t figure out how.

  8. Прогон сайта с помощью Хрумера может помочь улучшить позиции сайта в поисковых системах, повысить его трафик и увеличить количество потенциальных клиентов. Однако, не следует забывать, что использование Хрумера может повлечь за собой риск нарушения правил поисковых систем, таких как Google, что может привести к наказанию и снижению рейтинга сайта.
    соц закладки

  9. Heya! I’m at work surfing around your blog from
    my new iphone! Just wanted to say I love
    reading your blog and look forward to all your posts! Carry on the fantastic work!

  10. Pretty nice post. I simply stumbled upon your weblog and wanted to mention that I’ve truly enjoyed browsing your blog posts.

    In any case I’ll be subscribing to your feed and I’m hoping
    you write once more very soon!

  11. At this time it seems like WordPress is the preferred blogging
    platform available right now. (from what I’ve read) Is that what you are using on your

  12. Hello There. I discovered your weblog the use of msn. This is
    a very neatly written article. I will be sure to bookmark it and return to learn more of your useful information. Thanks for the post.
    I’ll definitely comeback.

  13. It’s actually a cool and helpful piece of info.
    I am satisfied that you just shared this useful
    info with us. Please stay us up to date like this.
    Thanks for sharing.

  14. Hi, i think that i saw you visited my site thus i came to “return the favor”.I am attempting to
    find things to enhance my site!I suppose its ok to use some of your ideas!!

  15. Incredible! This blog looks exactly like my old one! It’s on a completely different subject but it has pretty
    much the same page layout and design. Excellent choice of

  16. I know this if off topic but I’m looking into starting my own weblog and was curious what all is required to get setup?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very web smart so I’m not 100% sure. Any suggestions or advice would be greatly appreciated.

  17. I really love your website.. Pleasant colors &
    theme. Did you build this web site yourself?
    Please reply back as I’m wanting to create my own site and would love to
    learn where you got this from or exactly what the theme is called.

  18. I think this is among the most important info for
    me. And i am glad reading your article. But should remark on some
    general things, The website style is wonderful, the articles is really nice : D.
    Good job, cheers

  19. That is very fascinating, You are a very professional blogger.

    I’ve joined your feed and look forward to searching for extra of your
    great post. Additionally, I have shared your site in my social networks

  20. When I originally commented I clicked the “Notify me when new comments are added”
    checkbox and now each time a comment is added I get four emails with the same comment.
    Is there any way you can remove people from that service?

    Thanks a lot!

  21. When someone writes an post he/she retains the image of a user in his/her brain that how a user can be aware of it.
    Therefore that’s why this paragraph is outstdanding. Thanks!

  22. Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something.
    I think that you could do with a few pics to drive the message home a little bit,
    but other than that, this is wonderful blog. A great
    read. I will certainly be back.

  23. Its such as you read my mind! You seem to know so
    much approximately this, such as you wrote the book in it
    or something. I think that you simply can do with some percent to pressure the message house
    a little bit, but other than that, that is excellent blog.
    An excellent read. I will certainly be back.

  24. I’ve been following this amazing website for the past few days, it serves up great content for viewers. The site owner works hard to engage visitors. I’m a big fan and hope they keep up the good work!

Leave a Reply

Your email address will not be published. Required fields are marked *