Method to solve Linux xhost: unable to open display

Steps of setting up xhost under Linux Step 1: Log in to Linux as root and start the vnc service; Step 2: Set export DISPLAY=localhost:1 according to the port where vnc is up (1 means vnc is started on the first tty), see attachment 1 for the startup information of vnc; The third step: execute xhost +, and prompt "access control disabled, clients can connect from any host" is correct.

download-icon
Free Download
for VM, OS, DB, File, NAS, etc.
nick-zhao

Updated by Nick Zhao on 2022/07/29

Table of contents
  • Solution

X server provides graphics display services, and receive user input for the graphics applications (like Windows manager) to process. xhost is used to control the access permission of X server.


For example, when you want to use host A to log in host B, for applications, host A is the client; but for graphics, since they’re shown on host A, host A is the server, and X server on it needs to be used. To do this, you need to run xhost + on host A to have other users get permission to visit its X server.

 

However, when running xhost in Linux environment, there might be some users facing this unexpected issue: unable to open display. How to fix it?

 

Solution

Step 1: paste the following commands

[root@localhost ~]# vncserver  

 

New 'localhost:1 (root)' desktop is localhost:1  

 

Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/localhost:1.log  

 

[root@localhost ~]# export DISPLAY=localhost:1  

 

[root@localhost ~]# xhost +  

 

access control disabled, clients can connect from any host

 

Step 2: Login as root user

Type xdpyinfo command, record all strings behind name of display:

 

Execute xhost+ to get access control disabled, clients can connect from any host

 

If cannot get the corresponding result, type export DISPLAY=0 to redo it.

 

Execute xhost+ ip (the server which you want it to use the service)

 

Login as oracle user

 

If the string after name of display: under root login is 127.0.0.1:1.0

 

Then execute export DISPLAY=:1.0 as oracle user

 

Step 3: install Xshell 5

 

Step 4: Select the Linux system you want to connect, enter user name and password.

 

Step 5: Connection succeeds. startx command information appears.


Besides physical servers, X server can also be used on virtual machines. You can use Vinchin Backup & Recovery to backup VM data for complete data protection. 60-Day full-featured free trial available to download.

Share on:

Categories: Tech Tips
Free Trial Now close-icon