Ubuntu20.04 VNC installation and configuration implementation

Ubuntu20.04 VNC installation and configuration implementation

VNC is a remote desktop protocol. Follow the instructions in this article to remotely control Ubuntu 20.04 using VNC. The general VNC installation method cannot be used when the host is not connected to a monitor. The following operations can work properly whether the host has a monitor or not.

First install x11vnc

sudo apt-get install x11vnc -y

Set vnc password

sudo x11vnc -storepasswd /etc/x11vnc.pass

Create x11vnc autostart service

Create /etc/systemd/system/x11vnc.service and write the following content

[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth /run/user/1000/gdm/Xauthority -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc.pass -rfbport 5900 -shared
[Install]
WantedBy=multi-user.target

Start x11vnc service

sudo systemctl enable x11vnc
sudo service x11vnc start

At this point, if a monitor is connected to the remote host, it can be accessed through VNC on the LAN.

In order to ensure that the remote host can be accessed remotely through VNC regardless of whether it has a display, we need to make the following changes

Create a default xorg.conf file

sudo Xorg :1 -configure

At this time, the program will generate the /root/xorg.conf.new file

My default file content is as follows

Section "ServerLayout"
 Identifier "X.org Configured"
 Screen 0 "Screen0" 0 0
 InputDevice "Mouse0" "CorePointer"
 InputDevice "Keyboard0" "CoreKeyboard"
EndSection

Section "Files"
 ModulePath "/usr/lib/xorg/modules"
 FontPath "/usr/share/fonts/X11/misc"
 FontPath "/usr/share/fonts/X11/cyrillic"
 FontPath "/usr/share/fonts/X11/100dpi/:unscaled"
 FontPath "/usr/share/fonts/X11/75dpi/:unscaled"
 FontPath "/usr/share/fonts/X11/Type1"
 FontPath "/usr/share/fonts/X11/100dpi"
 FontPath "/usr/share/fonts/X11/75dpi"
 FontPath "built-ins"
EndSection

Section "Module"
 Load "glx"
EndSection

Section "InputDevice"
 Identifier "Keyboard0"
 Driver "kbd"
EndSection

Section "InputDevice"
 Identifier "Mouse0"
 Driver "mouse"
 Option "Protocol" "auto"
 Option "Device" "/dev/input/mice"
 Option "ZAxisMapping" "4 5 6 7"
EndSection

Section "Monitor"
 Identifier "Monitor0"
 VendorName "Monitor Vendor"
 ModelName "Monitor Model"
EndSection

Section "Device"
    ### Available Driver options are:-
    ### Values: <i>: integer, <f>: float, <bool>: "True"/"False",
    ### <string>: "String", <freq>: "<f> Hz/kHz/MHz",
    ### <percent>: "<f>%"
    ### [arg]: arg optional
    #Option "Accel" # [<bool>]
    #Option "AccelMethod" # <str>
    #Option "Backlight" # <str>
    #Option "CustomEDID" # <str>
    #Option "DRI" # <str>
    #Option "Present" # [<bool>]
    #Option "ColorKey" # <i>
    #Option "VideoKey" # <i>
    #Option "Tiling" # [<bool>]
    #Option "LinearFramebuffer" # [<bool>]
    #Option "HWRotation" # [<bool>]
    #Option "VSync" # [<bool>]
    #Option "PageFlip" # [<bool>]
    #Option "SwapbuffersWait" # [<bool>]
    #Option "TripleBuffer" # [<bool>]
    #Option "XvPreferOverlay" # [<bool>]
    #Option "HotPlug" # [<bool>]
    #Option "ReprobeOutputs" # [<bool>]
    #Option "XvMC" # [<bool>]
    #Option "ZaphodHeads" # <str>
    #Option "VirtualHeads" # <i>
    #Option "TearFree" # [<bool>]
    #Option "PerCrtcPixmaps" # [<bool>]
    #Option "FallbackDebug" # [<bool>]
    #Option "DebugFlushBatches" # [<bool>]
    #Option "DebugFlushCaches" # [<bool>]
    #Option "DebugWait" # [<bool>]
    #Option "BufferCache" # [<bool>]
 Identifier "Card0"
 Driver "intel"
 BusID "PCI:0:2:0"
EndSection

Section "Screen"
 Identifier "Screen0"
 Device "Card0"
 Monitor "Monitor0"
 SubSection "Display"
 Viewport 0 0
 Depth 1
 EndSubSection
 SubSection "Display"
 Viewport 0 0
 Depth 4
 EndSubSection
 SubSection "Display"
 Viewport 0 0
 Depth 8
 EndSubSection
 SubSection "Display"
 Viewport 0 0
 Depth 15
 EndSubSection
 SubSection "Display"
 Viewport 0 0
 Depth 16
 EndSubSection
 SubSection "Display"
 Viewport 0 0
 Depth 24
 EndSubSection
EndSection

Copy this file to /usr/share/X11/xorg.conf.d/xorg.conf

This file ensures that when a monitor is plugged into the host, the system interface can be displayed normally on the monitor. Next, we will add a virtual display to the system. When the host has no display, the system will use this virtual display.

Install virtual graphics driver

sudo apt install xserver-xorg-video-dummy

Add the following content at the end of this file

Section "Monitor"
 Identifier "Monitor1"
 HorizSync 1.0 - 2000.0
 VertRefresh 1.0 - 200.0
 # Add 16:9 modes, others are automatically detected.
 Modeline "1280x720" 74.48 1280 1336 1472 1664 720 721 724 746
 Modeline "1920x1080" 172.80 1920 2040 2248 2576 1080 1081 1084 1118
EndSection


Section "Device"
 Identifier "Card1"
 Driver "dummy"
 VideoRam 256000
EndSection

Section "Screen"
 DefaultDepth 24
 Identifier "Screen1"
 Device "Card1"
 Monitor "Monitor1"
 SubSection "Display"
  Depth 24
  Modes "1920x1080"
 EndSubSection
EndSection

In this way, we have created a virtual display using the virtual graphics card. In order to make both the virtual display and the real display work, we need to change the top ServerLayout

Section "ServerLayout"
    Identifier "X.org Configured"
    Screen 0 "Screen0" 0 0
 Screen 1 "Screen1" 0 0
EndSection

Now restart the remote computer and you can remote in without a monitor.

There is another problem with the above method. That is, if the user is not logged in, there is no way to remotely control it. So you need to set the user to log in automatically.

This is the end of this article about Ubuntu 20.04 VNC installation and setup. For more information about Ubuntu 20.04 VNC installation and setup, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solution to the startup error problem of AndroidStudio4.1 under Ubuntu
  • Solution to the error problem of Vscode remotely connecting to Ubuntu
  • Detailed tutorial on using VS Code and installing C/C++ plugins in Ubuntu
  • How to change password and set password complexity policy in Ubuntu
  • Ubuntu opens port 22
  • How to install and configure GitLab on Ubuntu 20.04
  • How to install vncserver in Ubuntu 20.04
  • Ubuntu configuration Pytorch on Graph (PoG) environment process diagram

<<:  MySQL parameter related concepts and query change methods

>>:  Uniapp realizes sliding scoring effect

Recommend

Mysql NULL caused the pit

Using NULL in comparison operators mysql> sele...

CSS3 mobile vw+rem method to achieve responsive layout without relying on JS

1. Introduction (1) Introduction to vw/vh Before ...

Detailed explanation of viewing and setting SQL Mode in MySQL

Viewing and Setting SQL Mode in MySQL MySQL can r...

Some conclusions on the design of portal website focus pictures

Focus images are a way of presenting content that ...

Gogs+Jenkins+Docker automated deployment of .NetCore steps

Table of contents Environmental Description Docke...

Programs to query port usage and clear port usage in Windows operating system

In Windows operating system, the program to query...

jQuery implements the bouncing ball game

This article shares the specific code of jQuery t...

Example code for hiding element scrollbars using CSS

How can I hide the scrollbars while still being a...

How to delete folders, files, and decompress commands on Linux servers

1. Delete folders Example: rm -rf /usr/java The /...

Example of automatic stop effect after text scrolling

The effect is very simple, just copy the following...

Vue template compilation details

Table of contents 1. parse 1.1 Rules for intercep...

Vue implements scroll loading table

Table of contents Achieve results Rolling load kn...