分享两则X相关的小技巧

13 views
Skip to first unread message

Qian Hong

unread,
Apr 12, 2011, 5:52:27 AM4/12/11
to gz...@googlegroups.com
火星了呵呵,刚刚知道ssh -Y 和 Xfake 这两个玩意,分享给同样火星的朋友看,顺便当作备忘.

0. 如果你用ssh远程连接一台主机,想开启远程主机上一个图形界面程序,直接运行一般是会出错的,
例如:
$ gedit

(gedit:24404): Gtk-WARNING **: cannot open display: 

如果远程主机运行着Xserver的话,那么只要指定 DISPLAY环境变量,就可以成功运行图形界面程序了
$ DISPLAY=:0.0 gedit
(不过这种情况可能不是很实用,因为图形界面是在远程主机上显示的,本地看不到)

假如远程主机连Xserver都没有怎么办呢?
1. 今天无意中看到的一则技巧:
在ssh连接的时候,加上参数 -Y ,就可以用本地的Xserver显示出远程主机上的图形界面程序:
man ssh
-Y      Enables trusted X11 forwarding.  Trusted X11 forwardings are not
             subjected to the X11 SECURITY extension controls.

$ ssh -Y -l testuser testhost
这时候,远程主机甚至不必运行Xserver

2. 采用1的方法有个缺点,就是当ssh连接断开的时候,远程主机的应用程序也会被关闭.
在某些特殊应用场合中,还可以有另一种方法,就是在远程主机安装Xfake.
Xfake的作用是欺骗主机,让主机以为有一个Xserver在运行,其实没有任何屏幕输出.
我搜了一下,找不到Xfake的deb包,但是找到一个叫做XVFB的,看起来跟Xfake是同一类
东西:

用法简单摘录如下:
在远程主机运行
$ Xvfb :1
其中 :1 是 DISPLAY 号

在本地主机通过ssh连接之后,可以用 DISPLAY=:1 运行带图形界面的程序,例如
$ DISPLAY=:1 wine freegate.exe

这样就不依赖本地的Xserver.如要在关闭ssh连接的时候仍保持进程运行,
只要利用screen就可以了.



--
Regards,
Qian Hong
-
Sent from Ubuntu
http://www.ubuntu.com/

Hex Lee

unread,
Apr 12, 2011, 10:44:49 AM4/12/11
to gz...@googlegroups.com
好东西,收藏了

--
您收到此邮件是因为您订阅了 Google 网上论坛的“广州 GNU/Linux 用户组”论坛。
要向此网上论坛发帖,请发送电子邮件至 gz...@googlegroups.com
要取消订阅此网上论坛,请发送电子邮件至 gzlug+un...@googlegroups.com
若有更多问题,请通过 http://groups.google.com/group/gzlug?hl=zh-CN 访问此网上论坛。

Qingping Hou

unread,
Apr 12, 2011, 10:47:02 AM4/12/11
to gz...@googlegroups.com
才知道有这玩意,受教了。

2011/4/12 Qian Hong <frac...@gmail.com>
--

刘洋

unread,
Apr 12, 2011, 11:32:07 AM4/12/11
to gz...@googlegroups.com
On Tue, Apr 12, 2011 at 05:52:27PM +0800, Qian Hong wrote:
> 火星了呵呵,刚刚知道ssh -Y 和 Xfake 这两个玩意,分享给同样火星的朋友看,顺便当作备
> 忘.
>
> 0. 如果你用ssh远程连接一台主机,想开启远程主机上一个图形界面程序,直接运行一般是
怎么是-Y,我一直用-X的?有什么区别呢?

源泉星火(张明源)

unread,
Apr 12, 2011, 10:19:35 PM4/12/11
to gz...@googlegroups.com
       -X     Enables  X11  forwarding.   This can also be specified on a per-
              host basis in a configuration file.

              X11 forwarding should be enabled with caution.  Users  with  the
              ability  to  bypass file permissions on the remote host (for the
              user's X authorization database) can access the local  X11  dis‐
              play  through the forwarded connection.  An attacker may then be
              able to perform activities such as keystroke monitoring.

              For this reason, X11 forwarding is  subjected  to  X11  SECURITY
              extension  restrictions  by default.  Please refer to the ssh -Y
              option and the ForwardX11Trusted directive in ssh_config(5)  for
              more information.


--
您收到此邮件是因为您订阅了 Google 网上论坛的“广州 GNU/Linux 用户组”论坛。
要向此网上论坛发帖,请发送电子邮件至 gz...@googlegroups.com
要取消订阅此网上论坛,请发送电子邮件至 gzlug+un...@googlegroups.com
若有更多问题,请通过 http://groups.google.com/group/gzlug?hl=zh-CN 访问此网上论坛。




--
明源
http://www.Linuxzh.org
Twitter: @muxueqz

forest chen

unread,
Apr 12, 2011, 10:32:59 PM4/12/11
to gz...@googlegroups.com
2011/4/12 Qian Hong <frac...@gmail.com>


假如远程主机连Xserver都没有怎么办呢?
1. 今天无意中看到的一则技巧:
在ssh连接的时候,加上参数 -Y ,就可以用本地的Xserver显示出远程主机上的图形界面程序:
man ssh
-Y      Enables trusted X11 forwarding.  Trusted X11 forwardings are not
             subjected to the X11 SECURITY extension controls.

$ ssh -Y -l testuser testhost
这时候,远程主机甚至不必运行Xserver

如果我的本地主机是 Windows,有没有办法。

Qian Hong

unread,
Apr 13, 2011, 12:37:45 AM4/13/11
to gz...@googlegroups.com


2011/4/13 forest chen <anyfo...@gmail.com>

在ssh连接的时候,加上参数 -Y ,就可以用本地的Xserver显示出远程主机上的图形界面程序:
man ssh
-Y      Enables trusted X11 forwarding.  Trusted X11 forwardings are not
             subjected to the X11 SECURITY extension controls.

$ ssh -Y -l testuser testhost
这时候,远程主机甚至不必运行Xserver

如果我的本地主机是 Windows,有没有办法。

我搜到一个叫做Xming的东西:
Xming is the leading X Window Server for Microsoft XP/2008/Windows7. It is fully featured, lean, fast, current, simple to install and because it is standalone native Microsoft Windows®, easily transported portable as a pocket X server.
Xming is totally secure when used with SSH and optionally includes an enhanced PuTTY Link SSH client and a portable PuTTY replacement package. Xming can work completely independent of the Window's registry when used with Xming-portablePuTTY.

hiphen lee

unread,
Apr 13, 2011, 2:48:36 AM4/13/11
to gz...@googlegroups.com
Mark.

btw, Xming是好东东啊。 
不过XDMCP协议的数据量实在很大,只适合局域网,所以Xserver/Xclient机制总觉得怪怪的。也许是我没有完全搞懂吧。。。

--
Hiphen

Liang Guo

unread,
Apr 13, 2011, 11:44:41 AM4/13/11
to gz...@googlegroups.com
cygwin里边带了一个Xserver,可以在windows上使用,用cygwin的兄弟可以试一下。

2011/4/13 Qian Hong <frac...@gmail.com>:


>
>
> 2011/4/13 forest chen <anyfo...@gmail.com>
>>>
>>> 在ssh连接的时候,加上参数 -Y ,就可以用本地的Xserver显示出远程主机上的图形界面程序:
>>> man ssh
>>> -Y Enables trusted X11 forwarding. Trusted X11 forwardings are not
>>> subjected to the X11 SECURITY extension controls.
>>> $ ssh -Y -l testuser testhost
>>> 这时候,远程主机甚至不必运行Xserver
>>
>> 如果我的本地主机是 Windows,有没有办法。
>
> 我搜到一个叫做Xming的东西:
> http://www.straightrunning.com/XmingNotes/
> Xming is the leading X Window Server for Microsoft XP/2008/Windows7. It is
> fully featured, lean, fast, current, simple to install and because it is

> standalone native Microsoft Windows(R), easily transported portable as a


> pocket X server.
> Xming is totally secure when used with SSH and optionally includes an
> enhanced PuTTY Link SSH client and a portable PuTTY replacement package.
> Xming can work completely independent of the Window's registry when used
> with Xming-portablePuTTY.
> --
> Regards,
> Qian Hong
> -
> Sent from Ubuntu
> http://www.ubuntu.com/
>

> --
> 您收到此邮件是因为您订阅了 Google 网上论坛的"广州 GNU/Linux 用户组"论坛。
> 要向此网上论坛发帖,请发送电子邮件至 gz...@googlegroups.com
> 要取消订阅此网上论坛,请发送电子邮件至 gzlug+un...@googlegroups.com
> 若有更多问题,请通过 http://groups.google.com/group/gzlug?hl=zh-CN 访问此网上论坛。
>

--
Liang Guo
http://bluestone.cublog.cn

Sense Zeng

unread,
Apr 14, 2011, 4:47:09 AM4/14/11
to gz...@googlegroups.com
谢谢,学习了

Alex.Sunday

unread,
Apr 20, 2011, 5:29:48 AM4/20/11
to gz...@googlegroups.com
本地主机做Xserver,远程指定DISPLAY变量,可以远程执行应用程序,算不算山寨的“云计算”啊~~~以前学校的时候折腾过,自己的电脑太差了,把linux玩友的电脑开放出来,自己在上面建一个Firefox 的Profile,然后运行一个Windows下的Xserver,然后利用别人的内存上自己的网~~~

在 2011年4月14日 下午4:47,Sense Zeng <opap...@gmail.com>写道:
谢谢,学习了


--
您收到此邮件是因为您订阅了 Google 网上论坛的“广州 GNU/Linux 用户组”论坛。
要向此网上论坛发帖,请发送电子邮件至 gz...@googlegroups.com
要取消订阅此网上论坛,请发送电子邮件至 gzlug+un...@googlegroups.com
若有更多问题,请通过 http://groups.google.com/group/gzlug?hl=zh-CN 访问此网上论坛。




--
★Sunday★

源泉星火(张明源)

unread,
Apr 21, 2011, 2:43:01 AM4/21/11
to gz...@googlegroups.com
我认为算。
但X的机制还是太慢了

Shens

unread,
Apr 22, 2011, 4:49:11 AM4/22/11
to gz...@googlegroups.com
只能说云计算的本质不在这,如果只讲效果的话,这样是相当于云计算的一部分效果,不过这早已有了。远程控制

2011/4/20 Alex.Sunday <alexsun...@gmail.com>

本地主机做Xserver,远程指定DISPLAY变量,可以远程执行应用程序,算不算山寨的“云计算”啊~~~以前学校的时候折腾过,自己的电脑太差了,把linux玩友的电脑开放出来,自己在上面建一个Firefox 的Profile,然后运行一个Windows下的Xserver,然后利用别人的内存上自己的网~~~



--
Yours sincerely,
Shens Lu(陆树燊)
MC Doing Studio
Sun Yet-sen University, Guangzhou

Reply all
Reply to author
Forward
0 new messages