• Windows/Linux 通过 ssh 打开 远程服务器 GUI程序


    背景

    在 Windows + ssh(Cygwin) + Linux(运行在虚拟机中的Ubuntu) 是一个很舒服的方案,但是偶尔需要用到 图形界面。

    如果需要通过ssh打开远程服务器端的程序,需要X11 forwarding。否则,会显示:

    $ gedit
    
    Failed to connect to Mir: Failed to connect to server socket: No such file or directory
    Unable to init server: Could not connect: Connection refused
    
    (gedit:49652): Gtk-WARNING **: cannot open display:
    
    

    经过搜索,我找到了有关的解决方案,这个方案适用于:

    • Cygwin
    • MobaXterm
    • Putty
    • 从Linux连接到Linux

    ssh 服务器配置

    这里以Ubuntu为例

    ubuntu安装ssh客户端和服务器 并做相对于配置:

    # 安装ssh 
    sudo apt-get install openssh-server -y
    
    # 配置允许X11转发(设置 X11 有关服务)
    cp /etc/ssh/sshd_config /tmp/sshd_config
    ## ssh 服务器添加配置
    echo "X11Forwarding yes" >>  /tmp/sshd_config
    sudo cp /tmp/sshd_config /etc/ssh/sshd_config
    # 让配置生效
    sudo service ssh restart
    
    # 如果需要 这一台主机连接到别的地方也想运行GUI程序
    ## ssh 客户端添加配置(ssh_config)
    cp /etc/ssh/sshd_config /tmp/ssh_config
    echo "ForwardAgent yes" >>  /tmp/ssh_config
    echo "ForwardX11 yes" >>  /tmp/ssh_config
    echo "ForwardX11Trusted yes" >>  /tmp/ssh_config
    sudo cp /tmp/ssh_config  /etc/ssh/ssh_config   
    
    

    ssh 客户端 的配置

    Cygwin

    ref using-remote-appscygwin_x11_forwarding

    Cygwin的方案是比较复杂的:

    • 在Cygwin中新安装3个包:xinitcygutils-x11xterm
    • 启动"XWin Server":建议是在启动菜单中:Cygwin-x - XWin server
    • 打开Cygwin,输入:export DISPLAY=:0.0
    • 登录:ssh -Y ${loginName}@{ipAddress} [-p ${port=22}]

    效果如图:

    另外一个 Linux

    以Ubuntu为例,同上文,需要安装 ssh客户端

    Ubuntu安装ssh客户端和服务器 并做相对于配置:

    # 安装ssh 
    sudo apt-get install openssh-server -y
    
    ## ssh 客户端添加配置(ssh_config)
    cp /etc/ssh/sshd_config /tmp/ssh_config
    echo "ForwardAgent yes" >>  /tmp/ssh_config
    echo "ForwardX11 yes" >>  /tmp/ssh_config
    echo "ForwardX11Trusted yes" >>  /tmp/ssh_config
    sudo cp /tmp/ssh_config  /etc/ssh/ssh_config   
    

    登录:ssh -X ${loginName}@{ipAddress} [-p ${port=22}]

    效果如图:

    Windows

    以下的软件为了支持图形界面,需要,额外安装有关服务:X Window 服务端 程序 XMing

    Xming只是在windows下实现了一个X服务端,X客户端还还是远程程序本身,ssh起传输作用

    运行XMing,运行后在托盘有图标,提示信息为”Xming Server:0.0” 。

    根据登录软件的不同,具体有一些设置差异。

    Putty

    Putty的设置很容易,只需要勾选这个设置即可:

    Category
    └── Connection
        ├── SSH
        └── X11 - Enable X11 forwarding
    

    效果如图:

    MobaXterm

    MobaXterm的设置很容易,只需要勾选这个设置即可:

    Session
    └── SSH
        └── Advanced SSH settings - X11-Forwarding
    
    

    效果如图:

  • 相关阅读:
    来实现一个缩水版Vuex
    vue中的适配:px2rem
    Vue.js的复用组件开发流程
    Vue调试神器之Vue.js devTools
    浅析Vue响应式原理(三)
    逐行粒度的vuex源码分析
    vue源码解读-目录结构
    Vue源码探究-虚拟DOM的渲染
    利用hash或history实现单页面路由
    passive的作用和原理
  • 原文地址:https://www.cnblogs.com/schips/p/12563373.html
Copyright © 2020-2023  润新知