LINUX設置VNC server配置服務客戶端和服務器
特別值得一提的是VNC server配置有很多值得學習的地方,這里我們主要介紹VNC server配置,包括介紹啟動VNC server服務等方面。對特定計算環境的支持使得每一個操作系統都有適合于自己的工作場合,這就是系統對特定計算環境的支持。遠程桌面設置在Fedora上設置VNC server。
一直想寫一下在redhat下詳細VNC server配置過程,以幫助一些向我有同樣需求卻有懶得去讀man page的朋友,后來在www.fedoranews.org上發現已經有人寫了一個教程,并且還不錯。干脆翻譯算了。大家可以直接去閱原文,我這里只是粗略地解釋一下,以方便那些不愿意讀字母的朋友.
什么是VNC?
VNC是虛擬網絡計算Virtual Network Computing的縮寫. 他是一個遠程控制程序,允許用戶在因特網的任何地方使用簡單的程序來和一個特定的計算機(服務器)進行交互. 兩個交互的計算機不一定非得是同一類型,所以你可以在家里的運行windows的PC上來察看辦公室里運行Linux的機器。VNC可以自由獲取并且有上百萬的人在使用,他們來自工業、學術和個人應用等不同層面. 更多的信息請訪問 http://www.realVNC.com/我的系統中已經有這個軟件了嗎?
鍵入下面的命令來檢查VNC客戶端和服務器是否已經安裝在你的系統中:
[tchung@tchung101 tchung]$ rpm -q VNC VNC-server
VNC-4.0-0.beta4.3.2
VNC-server-4.0-0.beta4.3.2
[tchung@tchung101 tchung]$
要把VNC server配置成一項系統服務,把你的用戶名稱加入到下面的VNC server配置文件中:
CODE:[Copy to clipboard][tchung@tchung101 tchung]$ sudo vi /etc/sysconfig/VNCservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the line below to start a VNC server on display :1
# as my 'myusername' (adjust this to your own). You will also
# need to set a VNC password; run 'man VNCpasswd' to see how
# to do that.
#
# DO NOT RUN THIS SERVICE if your local area network is
# untrusted! For a secure way of using VNC, see
# URL:http://www.uk.research.att.com/VNC/sshVNC.html
# VNCSERVERS="1:myusername"
VNCSERVERS="1:tchung"
在啟動VNC服務之前,讓我們用VNC passwd這個命令來創建一個VNC的口令注意這將同時在你的home目錄下,創建一個隱藏的目錄.VNC,其中有一個文件passwd保存著你的VNC口令.
CODE:[Copy to clipboard][tchung@tchung101 tchung]$ VNC passwd
Password:
Verify:
[tchung@tchung101 tchung]$ ls -d .VNC
.VNC
[tchung@tchung101 tchung]$ ls .VNC
passwd
[tchung@tchung101 tchung]$
現在來啟動VNC server服務.
CODE:[Copy to clipboard][tchung@tchung101 tchung]$ sudo /sbin/service VNC server start
Starting VNC server: 1:tchung [ OK ]
[tchung@tchung101 tchung]$
察看一下.VNC這個目錄的內容,應該類似于下面的東西.
CODE:[Copy to clipboard][tchung@tchung101 tchung]$ cd .VNC
[tchung@tchung101 .VNC]$ ls
passwd tchung101:1.log tchung101:1.pid xstartup
[tchung@tchung101 .VNC]$
編輯這個名為xstartup的腳本,注意到下面紅色的部分的注釋
將這兩行標記成紅色的內容前面的注釋符號去掉,否則你將只能得到一個什么都沒有的灰屏。
#!/bin/sh
# Uncomment the following two lines for normal desktop:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
[ -x /etc/VNC/xstartup ] && exec /etc/VNC/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
VNCconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
因為我們已經修改了啟動腳本,現在來重新啟動VNC server配置.
CODE:[Copy to clipboard][tchung@tchung101 tchung]$ sudo /sbin/service VNCserver restart
Shutting down VNC server: 1:tchung [ OK ]
Starting VNC server: 1:tchung [ OK ]
[tchung@tchung101 tchung]$
那么怎樣來連接到VNC server? 照下面使用客戶端的VNC viewer命令.
[tchung@tchung101 tchung]$ VNC viewer localhost:1
輸入你的VNC口令,看一下結果
更新:
在使用防火墻的情況下來連接到一個遠程系統,需要打開端口5901.
加入以下紅色的部分,然后重啟iptables服務。
[tchung@tchung101 tchung]$ sudo vi /etc/sysconfig/iptables
# Firewall configuration written by redhat-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0]
:FORWARD ACCEPT [0]
:OUTPUT ACCEPT [0]
:RH-Firewall-1-INPUT - [0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
[tchung@tchung101 tchung]$ sudo /sbin/service iptables restart
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
Applying iptables firewall rules: [ OK ]
[tchung@tchung101 tchung]$
Forrest Taylor 提供的TIP
讓VNC server配置接受兩個不同的用戶:
CODE:[Copy to clipboard]VNC SERVERS="1:tchung 2:thomasc"
當然你要為兩個用戶分別運行VNC passwd來設置口令. 并且在你的防火墻修改中,你應該明白VNC server使用端口5901給連接1用,如果象上面一樣要支持兩個用戶,應同時打開5901和5902.
遠程桌面設置part2:利用putty進行VNC + ssh tunneling
在前面有VNC server配置設置的文章(http://bbs.chinaunix.net/forum/viewtopic.php?t= 368552&highlight=yunqing)里, 我們已經可以在一個Linux的服務器上運行VNC server進行遠程訪問了,但需要注意的是,如果直接使用VNC viewer來進行訪問,有兩點不利因素:
1. 口令傳輸是明文,很容易被偵聽到.
2. 防火墻需要打開59xx端口,這在通常的單位里是不可能的.
幸運的是,我們有ssh這個強大的工具,象X11 Forwarding(另文論述),我們可以使用ssh隧道來保護通訊過程,下面就進行簡單介紹.
假設VNC server配置運行在服務器 myserver (ip地址為:192.168.x.x)的屏幕1,也就是偵聽 192.168.x.x:5901, 用戶名為foo
情形一: VNC server配置客戶端為Linux
這種情形很簡單,一般的Linux發行版本里面都默認安裝了ssh套件.
1. 用ssh登錄到服務器
ssh -L 5901:localhost:5901 -l foo myserver或者直接用ip地址
ssh -L 5901:localhost:5901 -l foo 192.168.x.x
2. 在本機的另外開的終端上,運行VNC viewer (或其它的類似工具)
VNC viewer localhost:1
情形二: VNC客戶端為windows
1. 下載一個ssh客戶端,個人推薦putty,只有一個程序,不需要安裝,簡單而功能齊全. 到這里下載http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
下載putty.exe到桌面上直接運行即可。
2. 運行putty,輸入服務器的ip地址,輸入一個名字,這里myserver作為session的名字,按save保存。見附圖一
3. 單擊對話框左邊的tunnels來選擇相關設置,在source port里輸入5901,在Destination里輸入localhost:5901,按Add添加,如附圖二
4. 單擊左邊session,回到session設置,按save重新保存。按open即可登錄到服務器。
5. 運行VNC-viewer (如果沒有,到這里下載http://www.real VNC.com/download.html,只要一個exe的文件就行) ,在Server里輸入localhost:1,見附圖三, 輸入口令后一個Linux的桌面就會出現在windows里,并且是非常安全的, Cool?
另請參閱:
遠程桌面設置part1:在Fedora上VNC server配置過程(轉譯) (http://bbs.chinaunix.net/forum/viewtopic.php?t=368552&highlight=yunqing)
【編輯推薦】