VNC鏈接遠程Ubuntu設置

一.windows 遠程軟件VNCViewer

這個很少說: 下載地址:http://www.realvnc.com/download/viewer/ubuntu

 

二.安裝 vnc-server

紅帽的rpm系安裝使用 vim

yum install tigervnc-server

debian 的deb系安裝使用windows

apt-get install vnc4server

再次安裝失敗, 提示:bash

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了。session

 

 

三. 修改VNC Password

vncpasswd

Password: ******
Verify:*****app

若是輸入vncpasswd 提示 : bash: vncpasswd: 未找到命令, 估計用的是yum 的  yum install vnc-server    記得是tigervnc-server哦。ssh

 

四.啓動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 相應的:端口就會變化一次fetch

在這裏,咱們看到的是一個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 useroot@120.55.65.20*

客戶端:

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
相關文章
相關標籤/搜索