SSH X-Forwarding
X 是 Linux 的图形显示服务,基于 Client/Server 架构,因此可以方便地实现 远程图形应用显示,其原理是一个图形应用(例如火狐浏览器)是一个 X client, 当这个 client 连接本机上的 X server,并在本地图形界面上显示时, 就是我们绝大多数情况下使用图形界面应用的场景。 当 client 连接远程的 server 时,就可以在远程图形界面上显示。
在 SSH X-Forwarding 场景中,我们首先通过 SSH 登录远程服务器, 启动服务器上的图形应用,但指定它的 X server 为我们本地的显示界面, 就实现了远程启动 GUI 应用的目标。
在笔记本上执行 ssh -X <host_name>
登录到服务器上后,如果 echo $DISPLAY
返回空值,就不能显示服务器上的 GUI 程序,解决方法:
SSH登录前先设置本机 DISPLAY
变量:
export DISPLAY=127.0.0.1:0
ssh -X <host_name>
如果登录后仍然没有 DISPLAY
,说明 SSH 客户端没有 X 系统,
如果使用 Windows 系统,可以用 Moba Xterm 作为 SSH client。
DISPLAY 命名格式
hostname:X.Y
其中 hostname
可以是IP地址,X
表示一个 输入/输出 群组序号,从0开始,
由一个键盘以及一个或者多个显示器组成,Y
表示群组 X
中显示器的序号,
也是从0开始。
在服务器上后执行 who -a
命令
xrdp
On Ubuntu/Mint server, run:
sudo apt install xrdp openbox obconf ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy
On Windows laptop, start a remote desktop, use your Linux system user account as the login username/password in remote desktop.
After connected, you login to the openbox environment. Use right click to start terminal, browser, or quit the openbox environment. You can also move, maximize, minimize, resize the window like in other desktop environment. And use Alt-tab to loop focus between all the windows.
OpenBox have not a built-in taskbar. You can install fbpanel or lxpanel for a simple taskbar.
xpra
Install: apt-get install xpra
;
I want to run Thunderbird on host 10.32.1.81:
ssh chad@10.32.1.81 xpra start :100 --start-child=thunderbird
xpra attach ssh:10.32.1.81:100
Now Thunderbird window appears. You can use "Attach" to add attachment from the disk of remote server, which means all GUIs from the "root" GUI can be accessed remotely.
When it's done, press "Ctrl-c" in the terminal window to close Thunderbird window. Do not click "close" button, it will kill the Thunderbird window in DISPLAY 100, and you can't visit it any more.
If you want visit this window later:
ssh chad@10.32.1.81 xpra list // so you get the $DISPLAY number 100
xpra attach ssh:10.32.1.81:100 // run this command in AppFinder (Alt-F2) instead of terminal
xpra detach ssh:81:100 // run this command in AppFinder (Alt-F2) instead of terminal
If you want clear all:
ssh chad@10.32.1.81 xpra stop :100 // run this command on remote server
If you want to attach to a xpra server on localhost, run xpra attach :100
;
Add a SSH alias for convenience:
Add 81
as alias of "chad@10.32.1.81" in ~/.ssh/config.
Then you can use xpra in the following way:
ssh 81 xpra start :111 --start-child=gedit
xpra attach ssh:81:111
ssh 81 xpra list
ssh 81 xpra stop :111