Ubuntu配置VNCServer,一定能用,不白屏灰屏
-
安装基础软件
1 2 3 4 5 6 7 8
sudo apt update sudo apt-get upgrade sudo apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal sudo apt install tightvncserver vncserver 注: 在防火墙上打开 VNC Server 的监听端口 VNC Server 用到了三个端口:5801(*)、5901(*)、6001
-
修改~/.vnc/xstartup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#!/bin/bash export $(dbus-launch) export XKL_XMODMAP_DISABLE=1 export XDG_CURRENT_DESKTOP="GNOME-Flashback:Unity" export XDG_MENU_PREFIX="gnome-flashback-" unset SESSION_MANAGER gnome-panel & gnome-settings-daemon & metacity & nautilus & gnome-terminal & # [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup # [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources autocutsel -fork xrdb $HOME/.Xresources xsetroot -solid grey vncconfig -iconic & x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" & gnome-session --session=gnome-flashback-metacity --disable-acceleration-check --debug &
-
启动
1 2
chmod +x ~/.vnc/xstartup vncserver :1
机器无显示屏情况-设置虚拟显示屏 [转自:https://leimao.github.io/blog/Remote-Linux-Desktop/]
Set Up Remote Linux Desktop
X Forwarding
We have to first enable X forwarding.
We SSH to the remote Linux computer with -XC
where X
is the X service and C
allows data compression.
|
|
We install xauth
if it has not been installed on the remote Linux computer.
|
|
Make sure X11Forwarding
is yes
in /etc/ssh/sshd_config
.
|
|
Restart OpenSSH.
|
|
Confirm X forwarding is enabled.
|
|
Quick test X forwarding with X applications.
|
|
The GUI of the X applications will show up on our local computer.
We could also try FireFox browser.
|
|
Linux Desktop Forwarding
We have run single X applications successfully. Can we forward the entire remote Linux desktop? Sure, we can.
We will have to install the following dependencies.
|
|
Run the following command on the remote Linux computer while we are still ssh -X
in.
|
|
The forwarded desktop will show up on our local computer.
Opening X applications from the forwarded desktop is fine. But we were not able to open terminal to run commands.
Linux Desktop Forwarding via VNC
A better way to forward the Linux Desktop is to use VNC service.
To install the VNC server, we will install tightvncserver
on the remote Linux computer.
|
|
Then we could start a virtual desktop with an id of 1
.
|
|
We could then connect to the remote Linux desktop using VNC client software on our local computer.
Remmina is installed by default on my local Ubuntu 20.04 LTS. Here we just have to input the remote Linux computer IP address with the VNC virtual desktop id, and press Enter
.
Remmina
The connection was successful. However, we only see gray screen and could not do anything.
To fix this problem, we disconnect the VNC connection and kill the virtual desktop.
|
|
We will install lxde
on the remote Linux computer.
|
|
We will modify the ~/.vnc/xstartup
by adding /usr/bin/startlxde
to it. The modified file will look like this.
|
|
Finally, restart VNC server.
|
|
This time, the remote Linux desktop shows correctly in Remmina.
Remote Linux Desktop
There are some inconvenience that copy and paste text between the local computer and the remote desktop does not work. To fix this problem, again, we disconnect the VNC connection and kill the virtual desktop.
|
|
We will install autocutsel
on the remote Linux computer.
|
|
We will modify the ~/.vnc/xstartup
by adding autocutsel -fork
to it. The modified file will look like this.
|
|
Finally, restart VNC server.
|
|
Now, we could copy and paste easily between the local computer and the remote desktop.