1

I am trying to start and X11 connection from my remote Linux server to my Local Windows machine.

I've downloaded Xming portable and if I start an ssh connection to my Linux machine and starts Firefox it is passed to Xming and shown on my Windows machine.

I have now tried to achieve the same in python. But I do not think I understand it correctly.

I'm using the following code

import paramiko
import time

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('server-1', username='me', password='xxxxxxx')
stdin, stdout, stderr = ssh.exec_command("firefox")

t = ssh.get_transport ()
chan = t.open_session ()
print(chan.request_x11())

print(stdout.readlines(), stderr.readlines())

time.sleep(100)

only to get the following error:

 Error: GDK_BACKEND does not match available displays

I've also read that python it self can start and Xll session. But for now I only need it to be forwarded to my Xming server.

I only understand the very basic of what an X11 connection does and all the examples I've seen here is for when the python script is running on Linux.

Regards

4

1 回答 1

0

我自己想通了。虽然我不完全了解细节,但我猜 Xming 必须连接到 SSH 套接字或其他东西。无论如何,我需要做的就是将我的命令更改为以下

stdin, stdout, stderr = ssh.exec_command("export DISPLAY=localhost:10.0; xterm & firefox &")

Firefox 在 Xming 中打开。另请注意,python 脚本在此处被阻止,直到 Firefox 应用程序再次关闭。

所以我的最终代码如下

import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('server-1', username='me', password='xxxx')
stdin, stdout, stderr = ssh.exec_command("export DISPLAY=localhost:10.0; xterm & firefox & env")


print(''.join(stdout.readlines()), ''.join(stderr.readlines()))

ssh.close()

由于 Xming 是一个命令行应用程序,它也应该可以从 Python 应用程序内部启动。

于 2017-03-06T06:35:54.973 回答