72

当我通过 SSH 运行一些程序时,例如firefox &,我得到一个错误

Error: no display specified 

我想打开许多显示器,仍然显示stdout每个程序的。

初始问题:如何指定显示以获得多显示程序?

Pablo Santa Cruz 给了我以下代码作为解决方案。我不明白。

$ export DISPLAY=yourmachine.yourdomain.com:0.0

$ firefox &

yourmachine命令中的和是什么yourdomain.com

4

12 回答 12

77

The way that X works is the same as the way any network program works. You have a server of some description (in this case, the X display server) which runs on a specific machine, and you have X clients (like firefox) that try to connect to that server to get their information displayed.

Often (on "home" machines), the client and server run on the same box and there's only one server, but X is powerful enough that this doesn't need to happen. It was built with the server/client separation built in from the start.

This allows you to do such wondrous things such as log on to your box (in text mode) halfway around the planet, tell it that the display server is the box you're currently on and, voila, the windows suddenly start appearing locally.

In order for a client to interact with a user, it needs to know how to find the server. There are a number of ways to do this. Many clients allow the -display or --displayoption to specify it:

xeyes -display paxbox1.paxco.com:0.0

Many will use the DISPLAY environment variable if a display isn't specifically given. You can set this variable like any other:

DISPLAY=paxbox1.paxco.com:0.0; export DISPLAY # in .profile
export DISPLAY=paxbox1.paxco.com:0.0 # in your shell
DISPLAY=paxbox1.paxco.com:0.0 firefox & # for that command (shell permitting)

The first part of the DISPLAY variable is just the address of the display server machine. It follows the same rule as any other IP address; it can be a resolvable DNS name (including localhost) or a specific IP address (such as 192.168.10.55).

The second part is X-specific. It gives the X "display" (X server) number and screen number to use. The first (display number) generally refers to a group of devices containing one or more screens but with a single keyboard and mouse (i.e., one input stream). The screen number generally gives the specific screen within that group.

An example would be:

+----------------------------------------+
|paxbox1.paxco.com|                      |
+-----------------+                      |
|                                        |
|  +----------+----+  +----------+----+  |
|  |Display :0|    |  |Display :1|    |  |
|  +----------+    |  +----------+    |  |
|  |               |  |               |  |
|  | +-----------+ |  |               |  |
|  | |Screen :0.0| |  |               |  |
|  | +-----------+ |  |               |  |
|  | +-----------+ |  |               |  |
|  | |Screen :0.1| |  |               |  |
|  | +-----------+ |  |               |  |
|  | +-----------+ |  | +-----------+ |  |
|  | |Screen :0.2| |  | |Screen :1.0| |  |
|  | +-----------+ |  | +-----------+ |  |
|  | +-----------+ |  | +-----------+ |  |
|  | |Screen :0.3| |  | |Screen :1.1| |  |
|  | +-----------+ |  | +-----------+ |  |
|  | +-----------+ |  | +-----------+ |  |
|  | | Keyboard  | |  | |  Keyboard | |  |
|  | +-----------+ |  | +-----------+ |  |
|  | +-----------+ |  | +-----------+ |  |
|  | |   Mouse   | |  | |   Mouse   | |  |
|  | +-----------+ |  | +-----------+ |  |
|  +---------------+  +---------------+  |
|                                        |
+----------------------------------------+

Here you have a single machine (paxbox1.paxco.com) with two display servers. The first has four screens and the second has two. The possibilities are then:

DISPLAY=paxbox1.paxco.com:0.0
DISPLAY=paxbox1.paxco.com:0.1
DISPLAY=paxbox1.paxco.com:0.2
DISPLAY=paxbox1.paxco.com:0.3
DISPLAY=paxbox1.paxco.com:1.0
DISPLAY=paxbox1.paxco.com:1.1

depending on where you want your actual windows to appear and which input devices you want to use.

于 2009-07-31T02:06:03.697 回答
22
$ export DISPLAY=yourmachine.yourdomain.com:0.0
$ firefox &
于 2009-04-24T03:39:27.103 回答
19

当您通过 SSH 连接到另一台机器时,您可以在 SSH 中启用 X-Forwarding,以便 X 窗口通过 SSH 隧道加密转发回您的机器。-X您可以通过附加到 ssh 命令行或ForwardX11 yes在 SSH 配置文件中进行设置来启用 X 转发。

要检查 X-Forwarding 是否设置成功(服务器可能不允许),只需尝试echo $DISPLAY输出类似localhost:10.0.

于 2009-07-08T01:09:03.597 回答
14

通过登录到您的服务器

ssh -X root@yourIP

编辑 /etc/ssh/sshd_config 文件,并将这一行添加到其中。

X11UseLocalhost no

重启sshd。对于 CentOS(检查您的发行版

/sbin/service sshd restart

检查你的显示器

echo $DISPLAY

你应该看到这个

yourIP:10.0

享受

firefox

了解更多信息

于 2018-02-17T10:35:37.063 回答
13

尝试

export DISPLAY=localhost:0.0
于 2009-07-08T01:18:08.820 回答
9

当通过 SSH 连接时,请不要尝试手动设置 $DISPLAY。
如果您连接 viaSSH -X并且 $DISPLAY 保持为空,这通常意味着无法建立加密通道。

您很可能缺少包裹xauthxorg-x11-xauth. 尝试使用以下命令将其安装在远程计算机上:

sudo apt-get install xauth

或者

sudo apt-get install xorg-x11-xauth

在那之后重新启动你的 SSH 连接。不要忘记使用SSH -X,以便将 X Window 输出转发到您的本地计算机。

现在echo $DISPLAY再次尝试查看 $DISPLAY 是否已被 SSH 恶魔自动设置。它应该向您显示带有 IP 地址和端口的行。

于 2017-10-30T11:53:57.990 回答
8

我遇到了类似的问题,所以也许这个答案会对某人有所帮助。

错误的原因Error: no display specified是 Firefox 正在启动,但远程主机上没有运行 X 服务器 (GUI)。您可以使用 X11 转发在远程主机上运行 Firefox,但在本地主机上显示它。在 Mac OS X 上,您需要下载XQuartz才能使用 X11 转发。没有它,您将没有$DISPLAY变量集,因此如果您尝试 and echo $DISPLAY,它将是空白的。

于 2014-12-31T04:31:51.037 回答
6

尝试安装xorg-x11-xauth软件包。

于 2013-03-11T10:36:35.413 回答
5

我今天遇到了类似的问题。所以,这是一个简单的解决方案:在对机器进行 SSH 时,只需添加Ctrl- Y

ssh user@ip_address -Y

登录后,输入firefox &。你很高兴。

于 2017-12-14T14:58:08.980 回答
1

即使我在 CentOS 6.8 中也面临同样的问题。

yum reinstall xorg*

结束当前会话并在 mobiXterm 等工具中打开另一个会话。确保会话在工具中启用了 X11 转发。

于 2017-01-27T10:09:38.203 回答
0

我通过vnc对X11了解的比较多。要指定显示以获得多显示程序,请导出 DISPLAY=IP:DisplayNum.ScreenNum

例如,

vncserver :2
vncserver -list
echo '$DISPLAY'=$DISPLAY 
export DISPLAY=:2  # export DISPLAY=IP:DisplayNum or export DISPLAY=:DisplayNum for localhost; So that can vnc connect and see the vnc desktop :2 if $DISPLAY is not :2.
echo '$DISPLAY'=$DISPLAY
于 2017-11-20T03:05:46.583 回答
0

我在输入 firefox 之前使用 xming 服务器使用以下命令 export DISPLAY=0:0

于 2021-07-25T08:01:27.913 回答