x11与paramiko转发

x11与paramiko转发,第1张

x11与paramiko转发
  • 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()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5673443.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存