- 该
x11
请求可能使用了MIT-MAGIC-cookie-1
您可能未正确处理的 - 直接使用ssh我看到它需要确认x11请求(cookie挑战?)
- 该
.Xauthority
文件也可能是一个问题 - 您可以尝试
strace
ssh进程并查看正常流程 - 在你的脚本,你可以替换
xterm
使用strace xterm
,并与上述比较。
一些链接:
- http://en.wikipedia.org/wiki/X_Window_authorization
- http://tech.groups.yahoo.com/group/ssh/message/6747
- http://answers.tectia.com/questions/523/how-do-i-enable-x11-forwarding-for-users-without-a-home-directory
祝好运。
编辑:建立 在 加里的答案 之上 ,具有多个x11连接。
#!/usr/bin/env pythonimport osimport selectimport sysimport getpassimport paramikoimport socketimport loggingimport Xlib.support.connect as xlib_connectLOGGER = logging.getLogger(__name__)# connection settingshost = '192.168.122.55'user = 'user'password = getpass.getpass()ssh_client = paramiko.SSHClient()ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())ssh_client.connect(host, username=user, password=password)del password# maintain map# { fd: (channel, remote channel), ... }channels = {}poller = select.poll()def x11_handler(channel, (src_addr, src_port)): '''handler for incoming x11 connections for each x11 incoming connection, - get a connection to the local display - maintain bidirectional map of remote x11 channel to local x11 channel - add the descriptors to the poller - queue the channel (use transport.accept())''' x11_chanfd = channel.fileno() local_x11_socket = xlib_connect.get_socket(*local_x11_display[:3]) local_x11_socket_fileno = local_x11_socket.fileno() channels[x11_chanfd] = channel, local_x11_socket channels[local_x11_socket_fileno] = local_x11_socket, channel poller.register(x11_chanfd, select.POLLIN) poller.register(local_x11_socket, select.POLLIN) LOGGER.debug('x11 channel on: %s %s', src_addr, src_port) transport._queue_incoming_channel(channel)def flush_out(session): while session.recv_ready(): sys.stdout.write(session.recv(4096)) while session.recv_stderr_ready(): sys.stderr.write(session.recv_stderr(4096))# get local displylocal_x11_display = xlib_connect.get_display(os.environ['DISPLAY'])# start x11 sessiontransport = ssh_client.get_transport()session = transport.open_session()session.request_x11(handler=x11_handler)session.exec_command('xterm')session_fileno = session.fileno()poller.register(session_fileno, select.POLLIN)# accept first remote x11 connectiontransport.accept()# event loopwhile not session.exit_status_ready(): poll = poller.poll() # accept subsequent x11 connections if any if len(transport.server_accepts) > 0: transport.accept() if not poll: # this should not happen, as we don't have a timeout. break for fd, event in poll: if fd == session_fileno: flush_out(session) # data either on local/remote x11 socket if fd in channels.keys(): channel, counterpart = channels[fd] try: # forward data between local/remote x11 socket. data = channel.recv(4096) counterpart.sendall(data) except socket.error: channel.close() counterpart.close() del channels[fd]print 'Exit status:', session.recv_exit_status()flush_out(session)session.close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)