LINUX設定VNC server佈建服務用戶端和伺服器

來源:互聯網
上載者:User

特別值得一提的是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)

  1. 介紹Ubuntu VNC遠端控制原理操作
  2. 學習手冊:SUSE Linux下安裝VNC
  3. 利用VNC遠程遙控Linux作業系統
  4. 教你如何使用VNC串連Linux伺服器
  5. 用SSH保護你的VNC遠端連線

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.