一.windows 遠端軟體VNCViewer
這個不多說: 下載下傳位址:http://www.realvnc.com/download/viewer/

二.安裝 vnc-server
紅帽的rpm系安裝使用
yum install tigervnc-server
debian 的deb系安裝使用
apt-get install vnc4server
再次安裝失敗, 提示:
404 Not Found [IP: 112.124.140.210 80]
Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/main/libx/libx11/libx11-xcb1_1.4.99.1-0ubuntu2.2_amd64.deb 404 Not Found [IP: 112.124.140.210 80]
Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/main/libx/libxfixes/libxfixes3_5.0-4ubuntu4.2_amd64.deb 404 Not Found [IP: 112.124.140.210 80]
Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/main/libx/libxi/libxi6_1.7.1.901-1ubuntu1~precise1_amd64.deb 404 Not Found [IP: 112.124.140.210 80]
Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/main/libx/libxv/libxv1_1.0.6-2ubuntu0.1_amd64.deb 404 Not Found [IP: 112.124.140.210 80]
Failed to fetch http://cn.archive.ubuntu.com/ubuntu/pool/main/x/x11-utils/x11-utils_7.6+4ubuntu0.1_amd64.deb 404 Not Found [IP: 112.124.140.210 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
提示讓apt-get update , update後
apt-get install vnc4server
就ok了。
三. 修改VNC Password
vncpasswd
Password: ******
Verify:*****
如果輸入vncpasswd 提示 : bash: vncpasswd: 未找到指令, 估計用的是yum 的 yum install vnc-server 記得是tigervnc-server哦。
四.啟動VNC server
vncserver
提示:
xauth: file /root/.Xauthority does not exist
New \'AYbZ:1 (root)\' desktop is AYbZ:1
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/AYbZ:1.log
五.連接配接vnc
用戶端連接配接vnc 使用端口為:1 每啟動一次vncserver 相應的:端口就會變化一次
在這裡,我們看到的是一個Linux指令行視窗
六.修改顯示界面
我們打開/root/.vnc/xstartup
vim /root/.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 &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
我們需要将最後一行“x-window-manager &”改為我們自己的Ubuntu圖形界面服務, Ubuntu有gnome、KDE、Unity等桌面環境。
如果是gnome桌面,改成gnome-session &;
如果是KDE桌面,改成startkde &;
如果是Unity桌面,首先去 /usr/share/gnome-session/sessions/下看桌面session的名稱,如果是ubuntu-2d,則将最後一行改為:
export STARTUP="/usr/bin/gnome-session --session=ubuntu-2d"
$STARTUP
------------------------
在這裡,一大波問題來襲
修改最後一行為:gnome-session &
重新開機vnc:
vncserver -kill :1
vncserver
vnc還顯示指令行視窗
好,我們知道,有可能是沒有安裝桌面環境。方法安裝:
第一步:安裝x-windows的基礎
apt-get install x-window-system-core
第二步:安裝登入管理器
apt-get install gdm
第三步:安裝桌面
apt-get install ubuntu-desktop
重新開機vnc:
vncserver -kill :1
vncserver
依舊顯示指令行視窗
打開配置中預設桌面(去掉配置中的#)
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc
理論上是可以了。 如果繼續無法看到桌面繼續向下看:
記得在啟動vncservier時生成個日志.log檔案。
檢視日志檔案
cat root/.vnc/AYbZ\:1.log
顯示如下錯誤:
error opening security policy file /etc/X11/xserver/SecurityPolicy
Could not init font path element /usr/X11R6/lib/X11/fonts/Type1/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/Speedo/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/misc/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/75dpi/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/100dpi/, removing from list!
Could not init font path element /usr/share/fonts/X11/75dpi/, removing from list!
Could not init font path element /usr/share/fonts/X11/100dpi/, removing from list!
我們安裝字型便是
apt-get install xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic
安裝完成時候,重新開機vncserver,再次檢視log日志檔案
Could not init font path element /usr/X11R6/lib/X11/fonts/Type1/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/Speedo/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/misc/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/75dpi/, removing from list!
Could not init font path element /usr/X11R6/lib/X11/fonts/100dpi/, removing from list!
在/usr/share/fonts/X11目錄下有字型檔案了,但/usr/X11R6/lib 目錄還是不存在字型
我們可以讓X11R6裡面軟連結到share/fonts字型目錄中
mkdir -r /usr/X11R6/lib # 沒有X11R6/lib 目錄
cd /usr/X11R6/lib/
ln -s /usr/share/fonts/X11 X11
再次重新開機vncserver
OK!
補充
在記憶體寸土寸金的伺服器端,桌面環境占用越少越好。Ubuntu-desktop至少400MB。發現了好用的xfce,安裝好僅占用180MB記憶體。
apt-get install xfce4
編輯~/.vnc/xstartup,添加:
sesion-manager & xfdesktop & xfce4-panel &
xfce4-menu-plugin &
xfsettingsd &
xfconfd &
xfwm4 &
通過ssh端口轉發加密VNC連接配接
VNC直接連接配接伺服器,在一網段的計算機有可能用wireshark/sniffer竊聽到使用者名和密碼,可以通過SSH進行加密端口映射來保證傳輸使用者名和密碼的時候也是加密
ssl -L 參數: -L 遠端端口:本地IP:本地端口 遠端user@遠端IP
ssh -L 5901:localhost:5901 [email protected]*
用戶端:
vncviewer localhost:1
通過wireshark可以看到用SSH協定進行了加密傳輸。
設定vnc分辨率大小
vncserver -geometry 1440x900
自定義vnc的連接配接端口号
配置檔案路徑
which vncserver
file /usr/bin/vncserver
修改vncserver檔案的内容:
$geometry = "1024x768";
$vncPort = 5900 + $displayNumber;
改為自定義分辨率、端口号:
$geometry = "1440x900";
$vncPort = 12012 + $displayNumber;
vnc的port是端口号+1display number的,是以此時桌面1的端口号就為12013; 重新開機vncserver。 用戶端連接配接時IP+port,
192.168.1.125:12013