In Linux/Unix operating systems, DISPLAY is used to set where the image is displayed. directly log on to the graphic interface or log on to the command line interface and use startx to start the graphics. The DISPLAY environment variable is automatically set to 0: 0. At this time, you can open the terminal and output the name of the graphics program (such as xclock) to start the program. The image is displayed in the local window. Enter printenv on the terminal to view the current environment variable. The output result contains the following content:
DISPLAY =: 0.0
You can use xdpyinfo to view more detailed information currently displayed.
The DISPLAY environment variable format is host: NumA. numB, host refers to the host name or IP address of the Xserver. The image is displayed on this host. It can be a Linux/Unix machine that has started the graphic interface, or Exceed installed, x-Deep/32 and other Windows Operating Xserver Windows machines. if the Host is empty, the Xserver runs on the local machine, and the graphics program (Xclient) connects to the Xserver using unix socket instead of TCP. when a TCP connection is used, NumA is the connected port minus the value of 6000. If NumA is 0, it indicates that it is connected to Port 6000; when the unix socket method is used for connection, it indicates the path of the connected unix socket. If it is 0, it indicates connecting to/tmp /. x11-unix/X0. numB is almost always 0.
If you use su username or su-username to switch to another user, and use the command
Export DISPLAY =: 0.0
When you set the DISPLAY environment variable and run a graphic program (such as xclock), you will receive the following error:
Xlib: connection to ": 0.0" refused by server
Xlib: No protocol specified
Error: Can t open display: 0.0
This is because Xserver does not allow other users' graphics to be displayed on the current screen by default. if you want other users' images to be displayed on the current screen, run the following command as the current login user, that is, the user before switching the identity:
Xhost +
This command will allow other graphical programs started by other users to display the graphics on the current screen.
If the configuration file/etc/ssh/sshd_config on the server contains:
X11Forwarding no
The client configuration file/etc/ssh/ssh_config contains:
ForwardX11 yes
Then, the DISPLAY environment variable is automatically set after ssh is sent from the client to the server, allowing the graphics program executed on the server to DISPLAY the graphics on the client. view the environment variables on the server as follows (the results are different)
DISPLAY = localhost: 10.0
Using netstat-lnp on the client, we can see that a program has listened to port 6010.
Tcp 0 0 127.0.0.1: 6010 0.0.0.0: * LISTEN 4827/1
If you want to allow graphical programs on a remote machine to DISPLAY the graphics on the Xserver of the local machine, in addition to setting the DISPLAY environment variable of the remote machine, you also need to set the Xserver of the Local Machine to listen to the corresponding TCP port. in Linux, TCP ports are no longer monitored by default for security reasons. you can modify the/etc/X11/xinit/xserverrc file
Exec/usr/bin/X11/X-dpi 100-nolistentcp
Change
Exec/usr/bin/X11/X-dpi 100
Allows you to start listening on the TCP port when you use the startx startup graph directly.
Modify/etc/kde3/kdm/kdmrc and set
ServerArgsLocal =-nolisten tcp
Change
ServerArgsLocal =
When kdm is allowed as the Display Manager, It listens to the corresponding TCP port when the session is started.
Modify/etc/TPD. conf, and add
DisallowTCP = false
Alternatively, select "Options"-> "Configure Login Manager... "Security Page, cancel" DenyTCP connections to Xserver ", allow the Display Manager to listen to the corresponding TCP port when starting the session.