天天看點

Ubuntu系統安裝VNC虛拟網絡控制台!/bin/shUncomment the following two lines for normal desktop:x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &x-window-manager &!/bin/bash

虛拟網絡控制台(VNC)是一個圖形桌面共享軟體,允許您使用鍵盤和滑鼠遠端控制另一台計算機。

系統環境

服務端:Ubuntu 18.04 Server LTS

用戶端:Windows10

用戶端VNC-Viewer 6.20下載下傳位址:

https://www.realvnc.com/en/connect/download/viewer/

安裝桌面環境

本實驗中安裝的系統沒有安裝桌面環境,我們需要自己安裝,如果已經安裝桌面了清跳過這一步。

我們可Ubuntu提供了許多桌面環境,可以選擇自己喜歡的桌面環境,在這裡選擇安裝Xfce4桌面:

bpang@ubuntu1804:~$ sudo apt install xfce4*

安裝VNC Server

安裝倉庫提供的vnc4server:

bpang@ubuntu1804:~$ sudo apt install vnc4server

運作vncserver指令建立一個初始配置并設定密碼:

bpang@ubuntu1804:~$ vncserver

You will require a password to access your desktops.

Password:

Verify:

New 'ubuntu1804:1 (bpang)' desktop is ubuntu1804:1

Creating default startup script /home/bpang/.vnc/xstartup

Starting applications specified in /home/bpang/.vnc/xstartup

Log file is /home/bpang/.vnc/ubuntu1804:1.log

Ubuntu 18.04 LTS安裝vncserver虛拟網絡控制台Ubuntu 18.04 LTS安裝vncserver虛拟網絡控制台

然後停止vncserver服務:

bpang@ubuntu1804:~$ vncserver -kill :1

Killing Xvnc4 process ID 10260

配置VNC Server

編輯使用者家目錄下面的.vnc/xstartup檔案

bpang@ubuntu1804:~$ vim .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 &

startxfce4 &

設定vncserver開機啟動

在/etc/init.d檔案夾下面建立vncserver檔案,export USER=’bpang’改成自己的使用者名

bpang@ubuntu1804:~$ sudo vim /etc/init.d/vncserver

!/bin/bash

export USER='bpang'

eval cd ~$USER

case "$1" in

start)

su $USER -c '/usr/bin/vncserver :1'
echo "Starting VNC server for $USER "
;;           

stop)

su $USER -c '/usr/bin/vncserver -kill :1'
echo "vncserver stopped"
;;           

*)

echo "Usage: /etc/init.d/vncserver {start|stop}"
exit 1
;;           

esac

exit 0

給vncserver添加執行權限

bpang@ubuntu1804:~$ sudo chmod +x /etc/init.d/vncserver

開機啟動設定

bpang@ubuntu1804:~$ sudo update-rc.d vncserver defaults

bpang@ubuntu1804:~$ sudo service vncserver start

用戶端遠端連接配接測試

在windows10用戶端打開VNC Viewer,輸入位址和回話端口号:

總結

如果需要将VNC伺服器配置為多個使用者啟動顯示,請使用vncserver指令建立初始配置并設定密碼,然後使用其他端口建立新的服務檔案。

繼續閱讀