ubuntu uses VNC to implement remote desktop

Preface

I installed Ubuntu 20.10 on the Raspberry Pi 4B. I want to realize a remote desktop connection through VNC for the next experiment.
However, I searched many blogs about VNC connection on the Internet and tried various methods, but there were always various problems. Either I could not connect, or the screen was black and gray when I connected. In short, various problems appeared. Reinstall After completing the system n times, a way to achieve it was finally found.
Note: Ubunt18.04, Ubuntu20.04 and Ubuntu20.10 have been tested, and they are all implemented normally

Windows edge

Install VNC Viewer, go to its VNC Viewer official website to download and install.
Insert picture description here

Ubuntu 端

Before setting up VNC, you need a graphical interface. If you don’t have one, you can execute the following code to install the graphical interface

sudo apt install ubuntu-desktop
apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal
sudo reboot #重启即可看到图形界面
1. Install x11vnc program
sudo apt-get install x11vnc
2. Install lightdm

Because the gnome graphical interface is used, in order to ensure the compatibility of x11vnc with the graphical interface, lightdm needs to be installed here

sudo apt-get install lightdm

The installation process will pop up a screen, select lightdm to
Insert picture description here

3. Create a configuration directory
sudo mkdir -pv /home/【USERNAME】/.vnc

Where **[USERNAME]** is replaced with your username

4. Generate the VNC connection password for the current user
sudo x11vnc -storepasswd 【Password】 /home/【USERNAME】/.vnc/passwd

Where **[Password] set the password when connecting to VNC, [USERNAME]** replace with your username
Insert picture description here

5. Generate VNC configuration file
cat>x11vnc.service<<EOF
[Unit] 
Description=Start x11vnc at startup. 
After=multi-user.target 
 
[Service] 
Type=simple 
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/【USERNAME】/.vnc/passwd -rfbport 5900 -shared 
 
[Install] 
WantedBy=multi-user.target
EOF

After the configuration file is generated, move it to the /lib/systemd/sydtem/directory

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

Modify permissions to root

sudo chown root:root /lib/systemd/system/x11vnc.service
6. Reload the service configuration file
sudo systemctl daemon-reload

Execute the following command to view the service startup status

sudo systemctl list-unit-files | grep x11vnc

Insert picture description here

7. Start the VNC service at boot
sudo systemctl enable x11vnc.service
8. Restart the system

Because the lightdm graphics management program was installed before, you need to restart the system

sudo reboot
9. Check out the listening port
sudo ss -tunlp

You can see that the listening port of x11vnc has been opened
Insert picture description here

Remote Connection

Open the VNC Viewer on the windows side and enter the IP address: 5900 to 192.168.6.6:5900start a remote connection. The password is the previously set password.
Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_44543463/article/details/113846220