Enable VNC on Linux

Written on
December 11, 2020
Achieved by
November 30, 2020
a picture of a terminal screen by Arget, courtesy Unsplash Arget WARNING: If you use XWayland, STOP READING. You are out of luck. This tutorial is for XORG only. Linux offers multiple ways to connect and manage your desktop or machine. In previous tutorials, I mentioned how SSH could improve productivity by enabling a user to perform multiple tasks on different machines without having to walk over to that machine to do it, and how samba shares between users on the same network allow for collaboration without fancy software. Today, we focus on Virtual Network Consoles (VNCs), which allow you to run an "x session" remotely, complete with a GUI.
First, we will download the X11VNC server from Synaptic. Open your mint menu, type "Package M" and click the result, which should resemble a teal icon with white arrows pointing in different directions. I keep Synaptic pinned to my menu. If you wish to do this, drag it from the results list with your mouse and place it in the left-most space of the menu until you see the icons move, then let your mouse click go. Enter your privileged password, then click "Authenticate".
When Synaptic opens, click the "Search" icon on the top right portion of the window and type "x11vnc" in the query. Two results are shown in the example below.
a screenshot of the search query for x11vnc in synaptic a screenshot of the results of the search query for x11vnc in synaptic a screenshot the prerequisites for x11vnc Click the white square next to "x11vnc" and select the option "Mark for Installation". It will offer to download the dependencies for you. Review the dependencies and click "Mark". Now click "Apply" on the top left of the window. You will be given a summary of the changes that will be made, as well as how much additional space will be taken up. If you're satisfied, click "Apply". The download window will appear, followed by the installation window. Click the "Details" chevron if you'd like to see how it's going.
a screenshot of the download summary for x11vnc a screenshot the individual files downloading for x11vnc a screenshot of the user being asked to confirm changes in synaptic for x11vnc Now that you've installed X11VNC, you'll need to set credentials for it, much like you did with samba shares. Open a terminal, and type the following:
x11vnc -storepasswd You will then be asked to set a password. If you're wondering why I chose X11VNC, it's because I can use more complex passwords with it. The limit appears to be 20, as if I try 30 or longer, I get a double-return bug that implies the passwords I entered did not match. TightVNC truncates to 8. Type your desired password combination now. You can copy and paste the result from your password manager, and repeat the process when it asks you to verify. If you are asked to save the password to the default location, say yes.
a screenshot of the vnc password prompt As the configuration currently stands, you will need to be logged into your PC in order to connect via VNC. This is simply unacceptable from a security standpoint, and I will insert some unorthodox advice that you may want to follow if you don't want to enable automatic login. Open a terminal and type the following command:
sudo ln -sf ~/.vnc /usr/lib/vnc This will create a symlink to the VNC password so that when we create a service file for X11VNC to start automatically, it will let you log in through lightdm without a user x session. Now, we need to create that startup file. Open a terminal, and type the following, one at a time, entering your privileged password when prompted:
cd /lib/systemd/system sudo nano x11vnc.service You will now be presented with what appears to be a simple word processor. Type the following into it. Use the arrow keys to navigate to the cursor position you seek. Nano doesn't word wrap, so if you notice a cutoff, adjust the window borders or reduce the text size by typing CTRL + [-] and it should all be visible. Here's what I typed (redactions made to preserve my security-minded choices):

ExecStart=/usr/bin/x11vnc -auth guess -loop -forever -shared -o /var/log/x11vnc.log -rfbauth /usr/lib/vnc/passwd -rfbport (redacted, choose any unprivileged port)
ExecStop=/usr/bin/killall x11vnc

Type CTRL + O to save the file, and press Enter to use the name you created. Now stay in the terminal and type the following commands, which will reset the port daemon and allow you to enable X11VNC at boot - enter privileged passwords if prompted:
sudo systemctl daemon-reload sudo systemctl enable x11vnc.service I would restart at this point just to make sure it works. I use Remmina to connect to VNC, and I provide a sample configuration in the image below. If you are accessing remotely, use the public IP followed by the port you specified in -rfbport. Supply the username and password you created for VNC and use that. If everything is working as it should, you should see the login window and not your desktop. If you are using Debian Buster and this process failed (could not create Xsession), you should install lightdm. Then it should work.
Only one x11vnc service should be running at a time. Auto-login affects the session creation process. If you need to make different sessions, I'd keep each in a separate .service file and disable the active session using systemctl disable before enabling another service. For sessions you only want users to watch, use the -viewonly modifier in the "ExecStart" parameter.
- 🎙
© 2021 Mass Transit Honchkrow, NicoD's SBCs | Last modified (none)