Wednesday, September 21, 2022

Running VNC or Other Program at Startup on Linux Mint 21 or other Linux Using Systemd

Linux Mint Screenshot from their page
Note:  If you are just trying to get "your" program to run on boot as a service in Linux, skip to the instructions at the bottom.  I expect these steps to work on any systemd based machine, and I will continue refining this to work on my own Debian laptops.  For now, it works beautifully on Linux Mint which is derived from Debian via Ubuntu.

...

Between power pops and other instabilities here in South Florida’s own FPL, and their abysmal service, I managed to build a server.  We literally had one power outage and multiple "pops" over the last week and the weather has been gentle recently.

No, really, FPL is the Comcast of electrical services. You need a generator, Battery Backup, filters and so on.  I lost two desktops before learning this and luckily laptops are better suited to take Utility Company Mishaps.

I need the server.  I was given a list of hardware, specifically a desktop server from about 10 years ago.  Acer Aspire Easystore H340.

Immediately I got a cable that terminated on the motherboard and turned my widescreen analog VGA monitor into an older style 1080 by 768 Square by stretching pixels.

Removed all drives and installed a laptop boot drive.

Turned off the Bios for booting from anything but USB Sticks and first hard drive.

I installed Linux Mint 21 Xfce from the ISO.

Since this machine is an appliance, I installed it completely stock – taking the most “normal” choices under install.

When it is installed, turn off all screensavers – my machine would be a headless server.  The password protecting screensaver that "came up" when it timed out as a security measure would crash the machine when you were connected with VNC.  My own machine is in my house, behind a firewall, and only turned on when I need it.  If it had Wake On LAN enabled it would be perfect for the task.  Apparently the original software from the discontinued M$ Windows Home Server product had it so it's a matter of proving it can be used.

The hardest part of headless is getting VNC to work on startup.  I went through a long list of distributions and a long list of software “tricks” to try to get it to work when you sign on it.

The answer is this link - https://community.linuxmint.com/tutorial/view/2334

I will reproduce its text literally from before.  Reason is that forum documentation often will disappear.  I use this blog as a scratch pad so I want this to be here 10 years down the road.

Secondly at time of writing, I could not find a “cookbook” of how to add VNC protocol to the machine except for this one.  The hang up was getting VNC to start as a Service at boot.

Thanks to Linux Mint and their excellent documentation, it works.  Mind you it was written for version 18 and mine is version 21, hence my leaving it here for me to see in the future.  As of today, this original is a 5 year old posting derived from something older.  I want to make sure I have it because it should work with any systemd based linux machine.

As I go onward, I will add the next steps – configuring a /etc/fstab to mount a drive optionally at boot, and the samba configuration.

For now, here is Linux Mint’s documentation on how to make a service start at boot.  I am presenting it literally as of my date of publishing, and I recommend that you find it there. This is really just a note taped to the underside of my keyboard for all to share.




HOWTO: Setup VNC Server (x11vnc) on Linux Mint 18


This tutorial was adapted from here.

1. Remove the default Vino server: (Note, LM 21 did not have vino)

sudo apt-get -y remove vino

2. Install x11vnc:

sudo apt-get -y install x11vnc

3. Create the directory for the password file:

sudo mkdir /etc/x11vnc

4. Create the encrypted password file:

sudo x11vnc --storepasswd /etc/x11vnc/vncpwd

You will be asked to enter and verify the password.  Then press Y to save the password file.

5. Create the systemd service file for the x11vnc service:

sudo xed /lib/systemd/system/x11vnc.service

Copy/Paste this code into the empty file:

[Unit]
Description=Start x11vnc at startup.
After=multi-user.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -noxdamage -repeat -rfbauth /etc/x11vnc/vncpwd -rfbport 5900 -shared

[Install]
WantedBy=multi-user.target

6: Reload the services:

sudo systemctl daemon-reload

7. Enable the x11vnc service at boot time:

sudo systemctl enable x11vnc.service

8. Start the service:

Either reboot or

sudo systemctl start x11vnc.service

No comments:

Post a Comment