Reference:
https://blog.csdn.net/weixin_39278265/article/details/118641412
https://help.aliyun.com/document_detail/59330.html?accounttraceid=7c0e01c2a3e24c01886e3ad00e1eaaaacquoi
Foreword:
First of all, remember to open ports 5900 and 5901 required by the VNC service.
The specific firewall release rules are as follows:
Add firewall rules: https://help.aliyun.com/document_detail/59086.htm?spm=a2c4g.11186623.0.0.47ed2d32nshzmw#section-zy8-x7r-9pl
If the ping still fails, you can check it ufw status and iptables -nL. If you don't see ports 5900 and 5901 inside, you can enter the following code to release:
ufw allow 5900/tcp
ufw allow 5901/tcp
1. Build a graphical interface
1. Run the following command to switch to the root user.
sudo su root
2. Update the software source.
sudo apt-get update
3. Install aptitude.
apt-get install aptitude
sudo aptitude update
4. Install desktop programs and related dependencies.
aptitude install ubuntu-desktop
sudo add-apt-repository main
sudo add-apt-repository universe
sudo add-apt-repository restricted
sudo add-apt-repository multiverse
apt install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal ubuntu-desktop
5. Install vnc4server.
aptitude install vnc4server
At this time, you will find that ubantu 20.04 has the following problem:
the software vnc4server was not found in the apt source.
#问题描述
Package 'vnc4server' has no installation candidate
Solution
We add in the file /etc/apt/sources.list
deb http://archive.ubuntu.com/ubuntu/ bionic universe
After adding, execute the following command to update and then reinstall vnc4server
sudo apt update
aptitude install vnc4server
6. Run the following command to start VNC.
vncserver
7. For the first startup, you need to set the VNC login password, enter the VNC login password and confirm the password, and enter n in the following prompt, and press Enter.
When the information shown in the following figure is echoed on the command line, it indicates that VNC is started successfully.
8. Run the following command to modify the xstartup configuration file of VNC.
vim ~/.vnc/xstartup
Delete all the original content and change it to the following content ( this will avoid the problem of gray screen ):
#!/bin/sh
autocutsel -fork
xrdb $HOME/.Xresources
xsetroot -solid grey
export XKL_XMODMAP_DISABLE=1
export XDG_CURRENT_DESKTOP="GNOME-Flashback:Unity"
export XDG_MENU_PREFIX="gnome-flashback-"
unset DBUS_SESSION_BUS_ADDRESS
gnome-session --session=gnome-flashback-metacity --disable-acceleration-check --debug &
Then save and exit vim.
9. Restart vncserver.
vncserver -kill :1 && vncserver :1
At this time, the graphical interface appears!
2. Solve the problem that copying and pasting cannot be done after VNC connection:
enter first
vim ~/.vnc/xstartup
At the end of the file add:
vncconfig &
Save and exit vim, then enter vncserver -kill :1 && vncserver :1 to restart vncserver to copy and paste.
3. Adjust the resolution
If you want to adjust the resolution of the desktop, you can enter the following code:
# 运行以下命令,关闭已启动的VNC
vncserver -kill :1
# 启动一个分辨率为1920x1080的VNC桌面
vncserver -geometry 1920x1080 :1