Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set DISPLAY variable in Linux

2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about how to set the DISPLAY variable in Linux, the editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

On Linux/Unix operating systems, DISPLAY is used to set where graphics are displayed. After logging in to the graphical interface or the command line interface directly, use startx to start the graphics, and the DISPLAY environment variable will be 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 graphics will be displayed on the local window. Enter printenv on the terminal to view the current environment variables, and the output results are as follows:

DISPLAY=:0.0

Use xdpyinfo to view more detailed information currently displayed.

The format of DISPLAY environment variables is as follows

Host:NumA.NumB

Host refers to the host name or ip address of the host where Xserver is located. The graphics will be displayed on this machine. It can be a Linux/Unix machine with a graphical interface enabled, or a Windows machine with Xserver running on Windows platforms such as Exceed and X-Deep/32. If Host is empty, it means that Xserver is running locally and the graphics program (Xclient) connects to Xserver using unix socket instead of TCP. When connecting using TCP, NumA subtracts 6000 from the connected port. If NumA is 0, it means connecting to port 6000. When connecting using unix socket, it indicates the path of the connected unix socket. If 0, it means connecting to / tmp/.X11-unix/X0. NumB is almost always 0. 5%.

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, you will receive the following error when you run a graphics program such as xclock:

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 graphics from other users' graphics programs to be displayed on the current screen by default. If you need the graphics of another user to be displayed on the current screen, you should execute the following command with the currently logged-in user, that is, the user before the identity switch

Xhost +

This command will allow graphics programs started by other users to display graphics on the current screen.

Between two Linux machines, if the server-side configuration file / etc/ssh/sshd_config contains

X11Forwarding no

The client profile / etc/ssh/ssh_config contains

ForwardX11 yes

The DISPLAY environment variable is automatically set from the client ssh to the server side, allowing graphics programs executed on the server side to display graphics on the client side. View the environment variables on the server as follows (this result is not the same when different)

DISPLAY=localhost:10.0

Using netstat-lnp on the client, you can see that there is a program listening on port 6010.

Tcp 0 0 127.0.0.1 6010 0.0.0.0 * LISTEN 4827Univer 1

If you want to allow graphics programs on the remote machine to display 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 on the corresponding TCP port. For security reasons, the current Linux system no longer listens to TCP ports by default. You can modify the / etc/X11/xinit/xserverrc file to set the

Exec / usr/bin/X11/X-dpi 100-nolisten tcp

Modify to

Exec / usr/bin/X11/X-dpi 100

Allows you to start snooping on TCP ports when you start graphics directly using startx.

Modify / etc/kde3/kdm/kdmrc to set the

ServerArgsLocal=-nolisten tcp

Modify to

ServerArgsLocal=

When kdm is allowed as the display manager, listen on the corresponding TCP port when starting the session.

Modify / etc/gdm/gdm.conf to add in the [Security] section

DisallowTCP=false

Or select "Options"-> "Configure Login Manager..." in the login window Security page, cancel "Deny TCP connections to Xserver", allow gdm as the display manager, start the session to listen to the corresponding TCP port.

For ORACLE installation

Execute under the root user directory

# xhost +

# su-oracle

$DISPLAY=:0.0;export DISPLAY

$cd / Disk (the installation file directory where oracle is located)

$. / runInstaller

This is how to set the DISPLAY variable in Linux. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report