VNC Viewer request timeout solution, gray screen solution (gnome or xfce4)

VNC Viewer request timeout

problem

When connecting to the virtual desktop through VNC Viewer, the connection timeout occurs. Generally, this problem occurs. First, consider whether it is caused by the wrong input of server IP or VNC port number.
After troubleshooting, confirm that the IP and port numbers are correct, and find the problem after trying various methods:

The server may have a firewall open, and some services cannot be accessed through the external IP of the server, resulting in connection timeout.

Solution

Just manually open the corresponding port number in the server, and VNC Viewer can access it.

First view the rules of the current firewall:

#To view the current rule and corresponding number, you need to use root permission
sudo iptables -L -n --line-number 


There are many rules below. The two ports in the figure are VNC related ports, one is the port of desktop 52 and the other is the port of desktop 9. There are only rules for 09 in the previous rules, and 52 in the figure is added later.

Since the port of desktop 52 was not opened in the previous rules, it was opened manually.
First, you need to obtain the port number of desktop 52. The default port of VNC starts from 5901, that is, the port of Desktop 1 is 5901 and the port number of corresponding desktop 52 is 5952. If you are not sure or in order to be safe, you can use the following command to view the port numbers of all vncs under individual users.

netstat -lp|grep -i vnc


You can get that the port number of desktop 52 is 5952

Then, manually add the rule of opening port 52 to the firewall rule as follows:

sudo iptables -I INPUT -p tcp --dport 5952 -j ACCEPT

After opening the port, the VNC Viewer can access the VNC corresponding to port 52.

gnome desktop gray screen

Note: the installation in gnome environment may not be successful. If your system is 16.04 or 18.04, turn back directly to see the scheme of xfce4.
After opening the desktop, it is in the gray screen state, and the mouse is in the shape of "X", so no operation can be performed.

If you have configured the xstartup file before and it works normally, you can try the command, install the packages required by gnome, or update these packages.

sudo apt-get install gnome-panel gnome-settings-daemon metacity nautilus gnome-terminal

After installation or update, if the screen is still gray, it indicates that it is an xstartup problem.

We open the Amax sys: 52.log file to view the desktop log:

Xvnc Free Edition 4.1.1 - built Feb 25 2015 23:02:21
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.
Underlying X server release 40300000, The XFree86 Project, Inc


Mon Nov  8 14:25:29 2021
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on port 5952
 vncext:      created VNC server for screen 0
error opening security policy file /etc/X11/xserver/SecurityPolicy
Could not init font path element /usr/X11R6/lib/X11/fonts/Type1/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/Speedo/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/misc/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/75dpi/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/100dpi/, removing from list!
Could not init font path element /usr/share/fonts/X11/75dpi/, removing from list!
Could not init font path element /usr/share/fonts/X11/100dpi/, removing from list!
sh: /home/liushuo/.vnc/xstartup: Permission denied

From the last sentence, the permission of xstartup file is insufficient. View the permission of xstartup:

You can see that xstartup has only read and write permissions, so we add execution permissions to xstartup.

chmod +x .vnc/xstartup


Then regenerate desktop 52

vncserver -kill :52
vncserver -geometry 1920x1080 :52

After opening the desktop, the menu bar can be displayed normally, and the program and terminal can run normally, but the desktop and icons cannot be displayed, and the program runs very slowly.

View log file:

Xvnc Free Edition 4.1.1 - built Feb 25 2015 23:02:21
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.
Underlying X server release 40300000, The XFree86 Project, Inc


Mon Nov  8 17:17:22 2021
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on port 5951
 vncext:      created VNC server for screen 0
error opening security policy file /etc/X11/xserver/SecurityPolicy
Could not init font path element /usr/X11R6/lib/X11/fonts/Type1/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/Speedo/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/misc/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/75dpi/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/100dpi/, removing from list!
Could not init font path element /usr/share/fonts/X11/75dpi/, removing from list!
Could not init font path element /usr/share/fonts/X11/100dpi/, removing from list!
/home/liushuo/.vnc/xstartup: line 16: gnome-settings-daemon: command not found
metacity-Message: 17:17:25.351: could not find XKB extension.

The reason is that there is no Gnome settings daemon command, that is, Gnome settings daemon is not installed successfully.
I have no problem installing through apt get, but I can't find the information of Gnome settings daemon through ps -A | grep gnome.

After working for a long time, I don't know where the problem is. Leaders who know the solution can communicate.
My xstartup is as follows:

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

# dbus-launch startxfce4
 
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
 
xsetroot -solid grey
vncconfig -iconic &
 
gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
gnome-terminal &

If your Gnome settings daemon works normally, the desktop should come out after modifying the permissions of xstartup.
If you have the same problem as me and your Ubuntu system is 16.04 or 18.04, you can choose to install another desktop environment: Xfce4.

xfce4 scheme

The installation method is also very simple. vncserver is installed by default. If it is not installed, use the following command to install it:

sudo apt-get install vnc4server

Then install xfce

sudo apt-get install xfce4

You can use the following command to check whether the installation is successful:

ps -A | grep xfce4


Modify the configuration file xstartup to:

#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

dbus-launch startxfce4

[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
xrdb $HOME/.Xresources

Then regenerate desktop 52

vncserver -kill :52
vncserver -geometry 1920x1080 :52


Attach the log file of VNC currently in normal use:

Xvnc Free Edition 4.1.1 - built Feb 25 2015 23:02:21
Copyright (C) 2002-2005 RealVNC Ltd.
See http://www.realvnc.com for information on VNC.
Underlying X server release 40300000, The XFree86 Project, Inc


Mon Nov  8 19:08:30 2021
 vncext:      VNC extension running!
 vncext:      Listening for VNC connections on port 5951
 vncext:      created VNC server for screen 0
error opening security policy file /etc/X11/xserver/SecurityPolicy
Could not init font path element /usr/X11R6/lib/X11/fonts/Type1/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/Speedo/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/misc/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/75dpi/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/100dpi/, removing from list!
Could not init font path element /usr/share/fonts/X11/75dpi/, removing from list!
Could not init font path element /usr/share/fonts/X11/100dpi/, removing from list!
/usr/bin/startxfce4: X server already running on display :51
gpg-agent[42352]: WARNING: "--write-env-file" is an obsolete option - it has no effect
gpg-agent: a gpg-agent is already running - not starting a new one

(xfce4-session:42337): xfce4-session-WARNING **: 19:08:34.025: gpg-agent returned no PID in the variables

(xfce4-session:42337): xfce4-session-WARNING **: 19:08:34.026: xfsm_manager_load_session: Something wrong with /home/liushuo/.cache/sessions/xfce4-session-amax-sys:51, Does it exist? Permissions issue?
vmware-user: could not open /proc/fs/vmblock/dev

(xfwm4:42355): xfwm4-WARNING **: 19:08:34.063: The display does not support the XRender extension.

(xfwm4:42355): xfwm4-WARNING **: 19:08:34.063: The display does not support the XComposite extension.

(xfwm4:42355): xfwm4-WARNING **: 19:08:34.063: The display does not support the XDamage extension.

(xfwm4:42355): xfwm4-WARNING **: 19:08:34.064: The display does not support the XFixes extension.

(xfwm4:42355): xfwm4-WARNING **: 19:08:34.064: Compositing manager disabled.

(xfsettingsd:42371): xfsettingsd-CRITICAL **: 19:08:34.076: RANDR extension is too old, version 1.1. Display settings won't be applied.
Xlib:  extension "XInputExtension" missing on display ":51.0".

(xfsettingsd:42371): xfsettingsd-CRITICAL **: 19:08:34.076: XI is not present.

(xfsettingsd:42371): xfsettingsd-CRITICAL **: 19:08:34.076: Failed to initialize the Xkb extension.

(xfsettingsd:42371): xfsettingsd-CRITICAL **: 19:08:34.076: Failed to initialize the Accessibility extension.

** (update-notifier:42372): WARNING **: 19:08:34.100: already running?
xfwm4-Message: 19:08:34.112: Unsupported keyboard modifier '<Super>Tab'

(polkit-gnome-authentication-agent-1:42374): GLib-CRITICAL **: 19:08:34.115: g_variant_new_string: assertion 'string != NULL' failed

(polkit-gnome-authentication-agent-1:42374): polkit-gnome-1-WARNING **: 19:08:34.116: Failed to register client: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files

(xfwm4:42355): xfwm4-WARNING **: 19:08:34.117: Cannot find visual format on screen 0
xfwm4-Message: 19:08:34.160: Unsupported keyboard modifier '<Super>Tab'

(nm-applet:42367): nm-applet-WARNING **: 19:08:34.220: GDBus.Error:org.freedesktop.NetworkManager.AgentManager.PermissionDenied: An agent with this ID is already registered for this user.

(nm-applet:42367): Gtk-WARNING **: 19:08:34.255: Can't set a parent on widget which has a parent
Failure: Module initialization failed

** (xfdesktop:42363): WARNING **: 19:08:34.472: Failed to set the background '/usr/share/backgrounds/xfce/xfce-teal.jpg': GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs: No such interface 'org.freedesktop.DisplayManager.AccountsService'

There are still some warnings, but the desktop is ready to use.

reference resources

Port:
https://www.jianshu.com/p/b3068288d80d
https://www.cnblogs.com/ding2016/p/8031926.html

vnc error Troubleshooting:
https://blog.csdn.net/CH_sir/article/details/107930881
https://junchu.blog.csdn.net/article/details/103974974
https://blog.csdn.net/qq695165856/article/details/105677776

Gray screen:
https://www.freesion.com/article/85721281890/

xfce4:
https://www.cnblogs.com/kerrycode/p/4790021.html
https://blog.csdn.net/weixin_34174422/article/details/93689750
https://www.linuxidc.com/Linux/2018-08/153435.htm

Tags: Linux Operation & Maintenance Ubuntu vnc server

Posted on Mon, 08 Nov 2021 13:33:43 -0500 by Vidya_tr