piątek, 11 kwietnia 2025

Starting TightVNC (vncserver) on boot in Linux Mint/Ubuntu

 I recently had to configure autostarting of VNC on a Linux Mint install that is used as a small home server.

What I found out is that most of guides on the internet just don't work.

I don't know if it's the new version of OS or TightVNC itself but all I got in logs was something like


vncserver.service - VNC Server for user [username]

Loaded: loaded (/home/[username]/.config/systemd/user/vncserver.service; enabled; preset: enabled)

Active: failed (Result: exit-code) since Thu 2025-04-10 00:37:39 CEST; 38s ago

Duration: 660us

Process: 2634 ExecStart=/usr/bin/vncserver :1 -geometry 1280x720 -depth 24 (code=exited, status=216/GROUP)

systemd[931]: vncserver.service: Scheduled restart job, restart counter is at 5.

systemd[931]: vncserver.service: Start request repeated too quickly.

systemd[931]: vncserver.service: Failed with result 'exit-code'.

systemd[931]: Failed to start vncserver.service - VNC Server for user [username].


 So I started tinkering and this is this is the only solutions that just worked for me

1. Install TightVNC Server:

sudo apt install tightvncserver

2. Create passwords for your install (as normal user)

vncpasswd 

2. Create a start script in your home directory

 nano ~/start_vnc.sh

3. Put this inside of the file

#!/bin/bash

/usr/bin/vncserver :1 -geometry 1280x720 -depth 24

4. If you want to have higher default resolution for your remote desktop, you can change the resolution in start command

  • 1680x1050  (I recommend this one)

/usr/bin/vncserver :1 -geometry 1680x1050 -depth 24

  • Full-HD
/usr/bin/vncserver :1 -geometry 1920x1080 -depth 24

5. Save & Exit nano (ctrl+o, ctrl+x)

6. Make this script executable

chmod +x ~/start_vnc.sh

7. Now let's create a script that will start the thing on system startup

nano ~/.config/systemd/user/vncserver.service

8. This are the contents:

[Unit]

Description=VNC Server

After=network.target


[Service]

Type=oneshot

ExecStart=/home/[PUT_YOUR_USERNAME_HERE]/start_vnc.sh

RemainAfterExit=yes

Restart=on-failure

Environment="XAUTHORITY=/home/[PUT_YOUR_USERNAME_HERE]/.Xauthority" "XDG_RUNTIME_DIR=/run/user/%U"

WorkingDirectory=/home/[PUT_YOUR_USERNAME_HERE]


[Install]

WantedBy=default.target 

 

9. Save & Exit

10. We need to register/enable the service, and do other boring stuff

systemctl --user daemon-reload

systemctl --user enable vncserver.service

systemctl --user start vncserver.service

 

11. And let's check if it started:

 systemctl --user status vncserver.service


If everything went well, you will see a line like:


You are now able to connect to your desktop using port 5901. In your VNCViewer app You need to enter the address like this:

192.168.0.123:5901

so 

Your.Server.Ip.Address:5901 

You can now reboot your machine and you'll be able to connect without having to login over ssh and starting vncserver manually.


Hope this helps.


One more thing.

During my experiments I installed and anabled linger for my user. I'm not sure if it is needed but if the above will not want to work for you, try this:


sudo loginctl enable-linger your-username

You need to reboot for it to work.

 

There is one more thing that you need to know.

This solution will not let you login into your normal desktop like on Windows. 

It will create a separate session on your machine and will run in the background. 

So you will not be able to see what's happening on your desktop if you go to the machine and do a normal graphical login. 

I tried achieving this but failed.