Linux下VNC配置使用總結:開啟+案頭配置+安全訪問

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   ar   color   os   使用   

作業環境:CentOS 5.3 + Windows XP SP3 32bit + RealVNC 4.1.2 i386 + TigerVNC.

參考:瀟湘隱者-Linux系統VNC配置實踐總結,薩米的部落格-VNC配置,孤葉風鈴-Linux 開啟VNCSERVER,遠端桌面設定:利用putty進行vnc + ssh tunneling

VNC是基於RFB(Remote FrameBuffer)的一款開源的遠端桌面控制軟體。目前,原來的AT&T版本已經不再使用,因為更多有重大改善的分支版本已經出現,像是RealVNC,VNC tight 和UltraVNC。Real VNC 是當前最活躍和強大的主流應用。

 一、安裝VNC Server

CentOS 5.3預設已經安裝vnc與vnc-server,對應的是realvnc的4.1.2版本。

對於沒有安裝vnc的Linux系統可以:

1、yum安裝,CentOS 5.3 yum源內建了vnc與vnc-server;

 [[email protected] ~]# yum install vnc [[email protected] ~]# yum install vnc-server

2、可以從realvnc官網下載,解壓歸檔後得到兩個rpm包,安裝vnc-server即可。

 

二、配置VNC Server

VNC Server的設定檔為 /etc/sysconfig/vncservers,在檔案末尾添加以下兩句:

VNCSERVERS="2:hubery"
VNCSERVERS="2:hubery"VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"
#案頭解析度為800*600 ,阻止圖形案頭通過TCP連接埠 ,不能通過WEB訪問vncserver,不能通過不安全的方式從遠程登入。

 關於參數配置說明:

1:-geometry 表示案頭解析度,預設為1024x768。

2:-nohttpd  表示不監聽HTTP連接埠(58xx)。

3:-nolisten tcp 表示不監聽TCP連接埠(60xx)

4:-localhost 只運行從本機訪問。

5:AlwaysShared 預設只允許一個VNCVIEWER串連,此參數表示同一個顯示連接埠允許多使用者同時登入.

6:-depth  表示色深,參數有8,16,24,32.

7: SecurityTypes None 登入不要求輸入密碼認證VncAuth預設值,要密碼認證。

 

由於root使用者使用的是第一個VNC Server,我們添加Server是從2開始的,所以這裡案頭號是2,使用者是hubery。

VNC使用的開始端點口是5900和5800,案頭號是2時,VNC Viewer訪問的連接埠是5902,WEB方式(java)訪問的連接埠號碼是5802。

root使用者的配置也是這個檔案,若要配置需要在檔案末尾同樣加上類似以上兩句。

 

三、防火牆配置

如果不熟悉防火牆iptables,可以直接關掉(重啟失效):

[[email protected] ~]# iptables -L

或

[[email protected] ~]# service iptables stop

但一般不建議這樣做,我們需要在防火牆裡開啟某些連接埠:

[[email protected] ~]# iptables -I INPUT -p tcp --dport 5901:5902 -J ACCEPT[[email protected] ~]# iptables -I INPUT -p udp --dport 5901:5902 -J ACCEPT

同樣,上述操作在電腦重啟之後也會失效,以下操作將配置儲存到設定檔,使其永久生效:

[[email protected] ~]# service iptables save

 

四、啟動VNC Server

在啟動Server之前需要給遠端控制設定一個訪問密碼:

[[email protected] ~]# su hubery[[email protected] root]$ vncpasswdPassword:Verify:[[email protected] root]$ vncserver :2xauth:  creating new authority file /home/hubery/.XauthorityNew ‘localhost:2 (hubery)‘ desktop is localhost:2Creating default startup script /home/hubery/.vnc/xstartupStarting applications specified in /home/hubery/.vnc/xstartupLog file is /home/hubery/.vnc/localhost:2.log[[email protected] root]$

 

五、VNC Viewer訪問

我的VNC用戶端是在Win XP下安裝的TigerVNC Viwer,可以從其官網免費下載。安裝VNC Viewer後以 Server_IP:案頭號 的形式訪問。

 

六、案頭配置(可選)

以上配置登陸之後得到的是twm案頭,看起來像一個終端,但它還是案頭,我們可以從命令列啟動案頭應用,例如firefox,但是一般人是用不習慣、不會去用它的,可以換其它的案頭嗎?當然可以,其設定檔為(使用者根目錄下)~/.vnc/xstartup,將twm修改為gnome-session或startkde即可切換成gnome或kde。

 

#!/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/.Xresourcesxsetroot -solid greyvncconfig -iconic &xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &# twm &gnome-session &

 

切換之後重啟服務是必須的:

[[email protected] .vnc]# service vncserver restart

 或

[[email protected] .vnc]# su hubery[[email protected] .vnc]$ vncserver -kill :2Killing Xvnc process ID 20353[[email protected] .vnc]$ vncserver :2New ‘localhost:2 (hubery)‘ desktop is localhost:2Starting applications specified in /home/hubery/.vnc/xstartupLog file is /home/hubery/.vnc/localhost:2.log[[email protected] .vnc]$


使用Viewer重新登陸,你會發現我們熟悉的案頭又回來了:

 

七、安全訪問VNC(可選)

如果直接使用vncviewer來進行訪問,有兩點不利因素:
1. 口令傳輸是明文,很容易被偵聽到.
2. 防火牆需要開啟59xx連接埠,這在通常的單位裡是不可能的.

幸運的是,我們有ssh這個強大的工具,象X11 Forwarding(另文論述),我們可以使用ssh隧道來保護通訊過程,下面就進行簡單介紹.

我依然使用Win XP下的Tiger VNC做用戶端,其實對於Linux下也是可以的(更簡單)。

1、在Session下配置Host Name為Server IP,Port為SSH連接埠22;

2、在Connection-》SSH-》Tunnels配置Source port為VNC Server連接埠號碼5902,Destination為localhost:5902,並Add添加;

 3、使用TigerVNC Viewer訪問,地址現在是localhost:2。

至此,我們使用了加密的VNC,而且也不需要配置防火牆開啟連接埠,也就是說使用ssh隧道在沒有步驟三的情況下也是有效。

Linux下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.