1. 程式人生 > >X遠端登入Linux主機(X11-forwarding)

X遠端登入Linux主機(X11-forwarding)

pediawiki對X11的定義如下:

The X window system (commonly X Window System or X11, based on its current major version being 11) is a computer software system and network protocol that provides a basis for graphical user interfaces (GUIs) and rich input device capability for networked computers. It creates a hardware abstraction layer where software is written to use a generalized set of commands, allowing for device independence and reuse of programs on any computer that implements X. ... Each person using a networked terminal has the ability to interact with the display with any type of user input device. Due to the ubiquity of support for X software on Unix, Linux and Mac OS X, X is commonly used to run client applications on personal computers even when there is no need for time-sharing.【

http://en.wikipedia.org/wiki/X11

即:X11是X Window System主版本11的縮寫,它不光是一個基本的GUI軟體,X11也被定義為一個網路協議,因為X11提供了非常靈活的網路訪問介面。

通過SSH 的 X11 forwarding訪問X11方便又安全

什麼是 X11 forwarding?

X forwarding是X的一個功能,它可以讓程式執行在一臺主機上,而使用者在另外一臺機器上與之互動。其概念上與VNC和微軟的遠端桌面類似,而與這些軟體不同,我們想要實現的是在Microsoft Windows平臺執行特定的圖形使用者介面程式,而不是顯示控制整個桌面。在X上下文中,客戶端“client”是指執行程式的主機,而你坐在伺服器“Server”前面,這點和常規的叫法不同。舉例來說,你通過A遠端開啟B上面的程式,也就是說你在操作A,而你要遠端控制B,那麼B就是客戶端,A是服務端。

Think of it this way: the X server is serving you, the human being, to the programs on the remote computer. The client, a program, makes requests of you through the X server by changing its graphical display, and you respond to it by clicking on it or typing into it.

SSH 的 X11 forwarding 特性可以使 X client 和 X server 安全地通訊。使用 X11 forwarding 後,從 X client 到 X Server 方向的資料先被送至 SSH server,SSH server 利用和 SSH client 的安全通道轉發給 SSH client,再由 SSH client 轉發給 X server,從 X server 到 X client 的資料流同理。這裡 SSH server 和 SSH client 充當了 X client 和 X server 間資料的轉發器,由於 SSH server 和 X client、SSH client 和 X server 一般在同一臺機器上,它們之間是一種安全的程序間通訊,而 SSH server 和 SSH client 間的通訊也是安全的,所以 X client 和 X server 間的通訊就是安全的。

需要哪些工具?

我們在Microsoft Windows平臺通過SSH訪問X11,參考上圖所示,那麼我們就需要:

1) SSH客戶端 - 這裡我們使用putty

2)X Server端 - 我們使用標準X.Org X server的Windows移植版本Xming

點選下載下面地址頁面裡的xming裡面的exe檔案下載(建議下載最近版)

注意這裡面有兩個xming和xming-mesa,前者用OpenGL展示介面,後者Mesa展示介面,對於一般使用者差別不大,任選一個即可

3)   字型庫:

點選下載下面地址頁面裡的xming-fonts裡面的字型庫exe檔案下載(建議下載最近版)

以上應用程式共putty免安裝,後面兩個是安裝包,直接點選預設安裝。 

執行

執行XMing後系統右下角托盤裡(工作列)多了X字樣的圖示,滑鼠放在上面會有類似“Xming server - 0:0”的字樣。

執行putty,在host name裡面填寫你的目標IP地址,例如“192.168.2.225”。在putty介面的左邊點選Connection/SSH/X11 子選單。選中"Enable X11 Forwarding", 在 "X display location"中輸入 "localhost:0:0" 。注意這裡的數字應該和滑鼠移到系統托盤裡顯示出來的數字一致(上面紅色字型),如果是“Xming server - x:y”那麼這裡應該是“localhost x:y”。 保持單選框"MIT-Magic-Cookie-1"不變。

點選左邊“Session”按鈕,輸入名字“MyPC”點選“Saved Sessions”儲存設定。然後雙擊開啟終端,輸入使用者名稱和密碼,執行gedit或者gnome-terminal試試。:-)

還有其他實現windows下訪問X11 forwarding的方案,例如

Cygwin/X - http://x.cygwin.com/

WeirdX - http://www.jcraft.com/weirdx/index.html

參考: