vnc server raspberry pi
Typically, a VNC server is installed on Raspberry Pi to remotely control the desktop. By VNC client you get a virtual desktop of Raspberry Pi on your own computer. With this remote desktop you can then remotely control Raspberry Pi or remotely control it.
VNC is especially useful if you prefer to work with a graphical desktop instead of using SSH on the console or if you want to peer over someone’s shoulder and provide remote support. The advantage is that screen content can be mirrored.
In the Linux environment, there are some VNC servers, all of which are more or less suitable. Many tutorials and tutorials use “tightvncserver”. He is extremely slim and can be set up quickly. Unfortunately he has a disadvantage. It does not support the appearance of the current desktop, but can only transfer additional virtual desktops.
If you want to access the currently visible desktop of Raspberry Pi via VNC, then let go of the fingers of TightVNCServer and use X11VNC.
To access Raspberry Pi via the VNC network, you need a VNC client. There are a lot of them. As a rule, one with a small range of functions, which is usually free, is sufficient. Therefore, here only a small selection.
- Windows: z. B. TightVNC
- Mac OS X: z. B. Chicken
- Linux: z. B. vncviewer (tigervnc) or others
- Obtain a suitable VNC client for your client PC.
- Install a VNC server on Raspberry Pi.
- Set up the VNC server to start automatically at boot time.
Of course, to be able to remotely control the desktop via VNC, Raspberry Pi must automatically start the desktop. To do this, set the start mode to “Enable Boot to Desktop / Scratch” with “raspi-config”. Optionally with or without automatic login by the user “pi”.
In addition, it is recommended to set the graphics memory in “raspi-config” under “Advanced Options> Memory Split” to the value 64 (MB).
For the settings to be adopted, Raspberry Pi needs to be restarted.
Solution: Install VNC server for virtual desktops
Note: Be careful not to have multiple VNC servers installed at the same time and start automatically at boot time. Before you install TightVNCServer, undo previous VNC server installation and configuration.
Install the VNC server TightVNCServer:
sudo apt-get update sudo apt-get install tightvncserver
Then we set up a password for the VNC client (recommended):
Here you have to enter a password and then confirm again. This password will be needed later for the VNC client on the remote machine. It is self-selectable and has nothing to do with the user password. It is the VNC server password.
The demand for a read only password can be denied.
After that we can start the VNC server manually.
Command to start a VNC session:
Then you can connect to Raspberry Pi with a VNC client. Please note that besides the hostname or the IP address of the Raspberry Pi you also have to specify port 5901 (eg 192.168.1.2:5901).
Note: The parameter “: 1” refers to the first virtual desktop. He has the port “5901”. If you want to operate more virtual desktops via VNC, then increase to “: 2”, etc. and select accordingly the port “5902” etc.
Parameters of TightVNCServer
Command to start a VNC session with additional parameters (optional):
vncserver: 1 -geometry 1920x1080 -depth 16 -name raspi -localhost
Command to end the VNC session:
vncserver: 1 -kill
–geometry: This parameter specifies the resolution of the desktop to be transmitted to the VNC client. In principle, one can specify any values here. But make sense only resolutions that can be displayed on the client. If the values are too large, then parts of the desktop are obscured and then you have to scroll in the window of the VNC client.
If you want to work on the VNC client with full screen, then you have to enter the resolution of the client here. But, the higher the resolution, the larger the volume of data to be transferred. That’s certainly not a problem on the local network. When transferring over the Internet already.
-depth: This parameter sets the color depth in bits of the images to be transferred. The best, color-detailed representation is obtained with the values of 24 or 32. However, this requires a correspondingly high bandwidth or transmission speed in order to be able to transmit the resulting data volume. As a rule, this can only be achieved in the local network. A value of 16 is certainly acceptable. A value of 8 is the minimum. The lower the value, the lower the data volume and the higher the bandwidth required.
-name: This parameter specifies the name to be displayed in the VNC client. This is interesting if you work with several VNC sessions on different systems and want to differentiate between the windows.
-localhost: This parameter prevents the VNC session from being established over the Internet in an unsecured manner. The idea here is to first establish a secure SSH connection and run the VNC session over it.
-kill: With this parameter you can end the VNC session.
Extension: VNC server autostart on the desktop
If you want to start the VNC server automatically when booting Raspberry Pis, then you have to create an autostart file.
In this file we add the following lines:
[Desktop Entry] Type = Application Name = TightVNC Exec = vncserver: 1 StartupNotify = false
Then save and close the file: Ctrl + O, Return, Ctrl + X.
Now you have to restart Raspberry Pi once.
Afterwards, if the desktop was started, also a VNC connection to Raspberry Pi should be possible.
Extension: Startup of TightVNCServer via systemd service
There is a second option to automatically start the TightVNCServer at boot time. And not via the autostart settings of the graphical desktop, but via a systemd service. This second variant has the advantage that you can control it a little finer, as long as you trust the command line.
First we create a new file in the systemd system directory:
sudo nano /etc/systemd/system/vncserver@.service
The contents of the file look like this:
[Unit] Description = VNC with TightVNCServer After = syslog.target network.target [Service] Type = forking User = pi PAMName = login PidFile = /home/pi/.vnc/% H:% i.pid ExecStartPre = - /usr/bin/vncserver - kill:% i> / dev / null 2> & 1 ExecStart = /usr/bin/vncserver -depth 24-geometry 1280x800:% i ExecStop = /usr/bin/vncserver -kill:% i [Install] WantedBy = multi-user.target
In the line that starts with “ExecStart …” there are the VNC parameters “-depth” and “-geometry”, which you can customize as you like.
Then save and close the file: Ctrl + O, Return, Ctrl + X.
Then you have to tell systemd that there is a new service / daemon.
sudo systemctl daemon-reload
The following commands explain how to control this VNC service on the command line.
Start VNC service:
sudo systemctl start firstname.lastname@example.org
Stop running VNC service:
sudo systemctl stop email@example.com
Show status of VNC service:
sudo systemctl status firstname.lastname@example.org
Switch on automatic booting at boot:
sudo systemctl enable email@example.com
Switch off automatic booting at boot time:
sudo systemctl disable firstname.lastname@example.org
Show if the VNC service starts automatically at boot time:
sudo systemctl is-enabled email@example.com
VNC is uncertain. All data (including passwords) are transmitted in plain text. Therefore you should only use VNC in the local network.
If Raspberry Pi can be reached via port forwarding (DNAT, port forwarding, DMZ) or directly from the Internet, then it can be attacked via the VNC server. In this case, the VNC should only be operated with the parameter “-localhost” and the VNC session should be established via SSH.
Alternative: Remote Desktop via RDP
In the Windows world, VNC is less common. This is called remote desktop support via RDP. If you’re working with Windows clients, setting up an RDP server on Raspberry Pi is a viable alternative to VNC.
Troubleshooting: Show currently visible desktop is not working
If you connect to Raspberry Pi with a VNC client in this way, you will not get the same desktop currently seen on Raspberry P, but a different one. The question is, how can that be?
You have to know that the VNC server starts a new instance of the X server. So an independent desktop. And that’s why you only have access to your own desktop via VNC client, not the current desktop. The TightVNCServer adjusts itself very stubbornly at the place.
To see the current desktop, you have to use X11VNC.