简体   繁体   English

如何将X11转发到运行在远程linux主机上的虚拟机?

[英]How to do X11 forwarding to a virtual machine running on a remote linux host?

I am running a virtual machine on a remote linux host: 我在远程linux主机上运行虚拟机:

my machine -> linux host -> virtual machine running on linux host 我的机器-> linux主机->在linux主机上运行的虚拟机

I have X11 forwarding enabled on the linux host, and on the virtual machine. 我在Linux主机和虚拟机上启用了X11转发。 I am trying to run JVisualVM on the virtual machine on my own machine launched using the ssh command (with ssh -X). 我试图在使用ssh命令(使用ssh -X)启动的我自己的计算机上的虚拟机上运行JVisualVM。

The ssh command I'm using is: 我正在使用的ssh命令是:

ssh -X -t root@linux_host -L 29998:localhost:29999 ssh -X -t -i /root/.ssh/my_key user@virtual_machine -L 29999:localhost:9999

Once I'm connected I set the display variable with: 连接后,我将显示变量设置为:

DISPLAY=<my machine's ip address>:0.0

Then I run JVisualVM with this, expecting the window to open on my own machine: 然后,我以此运行JVisualVM,期望在我自己的机器上打开该窗口:

/usr/java/jdk1.7.0_95/bin/jvisualvm -cp:a /opt/jboss/bin/client/jboss-cli-client.jar --jdkhome /usr/java/jdk1.7.0_95/

But I either get an error that the display is not set, or JVisual exits after a few seconds with an error code of 2. 但是我收到未设置显示的错误,或者JVisual几秒钟后退出,错误代码为2。

Since you're using ssh -X you're apparently expecting to use secure X forwarding with ssh. 由于您使用的是ssh -X您显然希望通过ssh -X使用安全的X转发。 In this case, ssh sould set the DISPLAY variable for you and your should NOT override it by setting DISPLAY manually. 在这种情况下,ssh souled为您设置了DISPLAY变量,您不应通过手动设置DISPLAY覆盖它。 If DISPLAY is not being set by ssh, that means that your ssh server setup has X forwarding disabled (for whatever reason), and you should fix that if at all possible. 如果ssh未设置DISPLAY则意味着ssh服务器设置已禁用X转发(无论出于何种原因),并且应尽可能解决此问题。

If you don't want to (or can't) use ssh X forwarding, you can use a direct connection (by setting DISPLAY as you are doing), but you ALSO need to open up the X server on your machine to remote connections. 如果您不想(或不能)使用ssh X转发,则可以使用直接连接(通过在进行操作时设置DISPLAY ),但是您还需要打开计算机上的X服务器以进行远程连接。 You do this with xhost on the local machine: 您可以在本地计算机上使用xhost进行此操作:

xhost <linux host address>

Note however, that this opens up your local machine to EVERYONE with acces to that linux host, or who can spoof that host address (which means basically everyone everywhere, unless you and the linux machine are inside a firewall), so this is NOT a good idea. 但是请注意,这将使您的本地计算机向所有人开放,并具有该Linux主机的访问权限,或者谁可以欺骗该主机地址(这意味着几乎每个地方的所有人,除非您和Linux计算机都在防火墙内),所以这不是好主意。

Try adding 尝试添加

X11UseLocalHost no X11UseLocalHost否

to

/etc/ssh/sshd_config / etc / ssh / sshd_config

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM