本文部份節錄和翻譯自http://fedoranews.org/tchung/vnc/index.shtml
(他真的寫的太優了...佩服佩服)
--------------------------------------------------
安裝VNC

打入下列指令去檢查用戶端和伺服器是否有安裝好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]$

--------------------------------------------------
修改vncservers的設定檔
請自行加入多出來的指令

[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"
(↑加入上面這行,tchung改成linux可登入帳號)

--------------------------------------------------
建立密碼檔

再還沒運作VNC時,我們先用vncpasswd指令 建立一個密碼檔
(這個密碼檔會在家目錄建立一個隱藏目錄.vnc)

[tchung@tchung101 tchung]$ vncpasswd
Password:
Verify:
[tchung@tchung101 tchung]$ ls -d .vnc
.vnc
[tchung@tchung101 tchung]$ ls .vnc
passwd
[tchung@tchung101 tchung]$


--------------------------------------------------
讓VNC執行成服務

[tchung@tchung101 tchung]$ sudo /sbin/service vncserver start
Starting VNC server: 1:tchung [ OK ]
[tchung@tchung101 tchung]$

讓我們來看看.vnc目錄有什麼內容,你應該會跟我有差不多的東西

[tchung@tchung101 tchung]$ cd .vnc
[tchung@tchung101 .vnc]$ ls
passwd tchung101:1.log tchung101:1.pid xstartup
[tchung@tchung101 .vnc]$

--------------------------------------------------

修改xstartup的內容

修改xstartup的內容,將紅色部分的註解拿掉
要不然你只能看到一片灰色的螢幕和指令列
(以下是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 &

我們才剛剛修改過xstartup 讓我們先重新起動vnc服務

[tchung@tchung101 tchung]$ sudo /sbin/service vncserver restart
Shutting down VNC server: 1:tchung [ OK ]
Starting VNC server: 1:tchung [ OK ]
[tchung@tchung101 tchung]$

我們如何連上vncserver? 用vncviewer 指令來達成目的

[tchung@tchung101 tchung]$ vncviewer localhost:1

--------------------------------------------------
防火牆  打開port 5901

UPDATE:
如果要讓遠端能夠連過來,防火牆的port 5901需要打開(放行)
加入下列紅色部分來打開port 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:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0: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]$

--------------------------------------------------
當使用二個使用者時
TIP by Forrest Taylor

如果要在vncservers使用二個使用者,照以下部驟

VNCSERVERS="1:tchung 2:thomasc"
當然你也要執行vncpasswd 去分別設定這二個使用者,當然你的防火牆要改動設定
你可能要確定VNC的 連線1 是不是用 port 5901,如果你有二個使用者以上的話
你可能要開啟(放行) port 5901port 5902
創作者介紹

清新下午茶

Johnny 鋼鍊 發表在 痞客邦 PIXNET 留言(0) 人氣()