Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
deb10:vnc [2022/12/01 22:58] – [Setup as service] Bernard Condraudeb10:vnc [2025/08/04 14:59] (current) Bernard Condrau
Line 1: Line 1:
 ====== VNC ====== ====== VNC ======
 +  * [[https://www.howtoforge.de/anleitung/wie-installiere-ich-vnc-server-unter-debian-12/|VNC Server unter Debian 12 installieren]]
 +
 ===== Installation ===== ===== Installation =====
-  - Install [[https://www.tightvnc.com/|TightVNC]]:<code>sudo apt install tightvncserver</code> +  - Install [[https://www.tightvnc.com/|TightVNC]]:<code>sudo apt install tightvncserver</code> 
-  - Open the ports in your [[deb9:ufw|UFW Firewall]]:<code>sudo ufw allow VNC +  - Open the ports in your [[deb9:ufw|UFW Firewall]]:<code>sudo ufw allow VNC 
-sudo ufw allow 5902/tcp</code>+sudo ufw allow 5902/tcp</code>
   - Establish a port forward for port 5902 for your client's SSH connection, and open an SSH connection to the server   - Establish a port forward for port 5902 for your client's SSH connection, and open an SSH connection to the server
   - Check connections to the VNC server with a [[https://www.realvnc.com/en/connect/download/viewer/windows/|VNC Viewer for Windows]], or on a mobile client [[https://play.google.com/store/apps/details?id=com.realvnc.viewer.android&hl=en_US|VNC Viewer for Android]]. Connect to localhost:5902.   - Check connections to the VNC server with a [[https://www.realvnc.com/en/connect/download/viewer/windows/|VNC Viewer for Windows]], or on a mobile client [[https://play.google.com/store/apps/details?id=com.realvnc.viewer.android&hl=en_US|VNC Viewer for Android]]. Connect to localhost:5902.
Line 9: Line 11:
 ===== Setup as service ===== ===== Setup as service =====
   - Next, we’ll set up the VNC server as a systemd service so we can start, stop, and restart it as needed, like any other service. This will also ensure that VNC starts up when your server reboots.   - Next, we’ll set up the VNC server as a systemd service so we can start, stop, and restart it as needed, like any other service. This will also ensure that VNC starts up when your server reboots.
-  - First, create a new unit file called /etc/systemd/system/vncserver@.service using your favorite text editor:<code>sudo vim /etc/systemd/system/vncserver@.service</code>+  - First, create a new unit file called /etc/systemd/system/vncserver@.service using your favorite text editor:<code>sudo vim /etc/systemd/system/vncserver@.service</code>
   - The @ symbol at the end of the name will let us pass in an argument we can use in the service configuration. We’ll use this to specify the VNC display port we want to use when we manage the service:<code>[Unit]   - The @ symbol at the end of the name will let us pass in an argument we can use in the service configuration. We’ll use this to specify the VNC display port we want to use when we manage the service:<code>[Unit]
 Description=Start TightVNC server at startup Description=Start TightVNC server at startup
Line 27: Line 29:
 [Install] [Install]
 WantedBy=multi-user.target</code>The ExecStartPre command stops VNC if it’s already running, make sure the command is preceded by a "-". The ExecStart command starts VNC and sets the color depth to 24-bit color with a resolution of 1920x1080 and dpi to 96 which ensures the fonts are large enough. WantedBy=multi-user.target</code>The ExecStartPre command stops VNC if it’s already running, make sure the command is preceded by a "-". The ExecStart command starts VNC and sets the color depth to 24-bit color with a resolution of 1920x1080 and dpi to 96 which ensures the fonts are large enough.
-  - Make the system aware of the new unit file<code>sudo systemctl daemon-reload</code> +  - Make the system aware of the new unit file<code>sudo systemctl daemon-reload</code> 
-  - Enable the unit file:<code>sudo systemctl enable vncserver@1.service</code>The 2 following the @ sign signifies which display number the service should appear over, in this case the default :1.+  - Enable the unit file:<code>sudo systemctl enable vncserver@1.service</code>The 2 following the @ sign signifies which display number the service should appear over, in this case the default :1.
   - Stop the current instance of the VNC server if it’s still running:<code>vncserver -kill :1</code>   - Stop the current instance of the VNC server if it’s still running:<code>vncserver -kill :1</code>
   - Check that the following files do not exist. If they do, delete them:<code>/tmp/.X2-lock   - Check that the following files do not exist. If they do, delete them:<code>/tmp/.X2-lock
 /tmp/.X11-unix/X2</code> /tmp/.X11-unix/X2</code>
-  - Then start it as you would start any other systemd service:<code>sudo systemctl start vncserver@1</code> +  - Then start it as you would start any other systemd service:<code>sudo systemctl start vncserver@1</code> 
-  - Check the service is active with one of the following commands:<code>sudo systemctl is-active vncserver@1 +  - Check the service is active with one of the following commands:<code>sudo systemctl is-active vncserver@1 
-sudo systemctl status vncserver@1</code>+sudo systemctl status vncserver@1</code>
   * Your VNC server will now be available when you reboot the machine.   * Your VNC server will now be available when you reboot the machine.
  
 ===== Delay starting the service ===== ===== Delay starting the service =====
 In my setup I attach the hard disks only after the encryption has been confirmed by password. This makes running the service at boot time not possible. In this case, you need to start the vncserver after the hard disk has been attached and the user folders are available. In my setup I attach the hard disks only after the encryption has been confirmed by password. This makes running the service at boot time not possible. In this case, you need to start the vncserver after the hard disk has been attached and the user folders are available.
-  - Disable the unit file:<code>sudo systemctl disable vncserver@1.service</code> +  - Disable the unit file:<code>sudo systemctl disable vncserver@1.service</code> 
-  - Add the starting of the service through a script which runs at boot time, for example rc. local<code>sudo systemctl start vncserver@1.service</code>+  - Add the starting of the service through a script which runs at boot time, for example rc. local<code>sudo systemctl start vncserver@1.service</code> 
 + 
 +===== Snap ===== 
 +  - If you need to access applications installed with ''snapd'' through your VNC connection you need to tweak the permissions to access the X server. 
 +  - Run the following command before invoking such an application<code>$ xhost +</code> 
 +  - The initial access control list for display number n may be set by the file ''/etc/Xn.hosts'', where ''n'' is the display number of the server. If this file exists and contains the following line running ''xhost'' is not required.<code>local:</code>
  
 ===== Links ===== ===== Links =====