我本身本人使用樹莓派,就是ssh鏈接操做;可是因爲實施的部分同窗不熟悉Linux命令行操做,雖然以前我給搞過teamviewer方式,可是對他們而言,仍是有點複雜,他們也不喜歡不熟悉用ssh,因此我嘗試了一下,給他們搞了一下vnc,之後他們能夠圖形化去操做,相對比較便捷。html
在前面先把相關命令寫一下,有須要的直接複製一次性執行下去;java
#安裝
sudo apt-get install tightvncserver -y
#設置密碼 vncpasswd #設置開機啓動 sudo vi /etc/init.d/tightvncserver
shell 腳本:linux
#!/bin/sh ### BEGIN INIT INFO # Provides: tightvncserver # Required-Start: $local_fs # Required-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/stop tightvncserver ### END INIT INFO # More details see: # http://www.penguintutor.com/linux/tightvnc ### Customize this entry # Set the USER variable to the name of the user to start tightvncserver under export USER='pi' ### End customization required eval cd ~$USER case "$1" in start) # 啓動命令行。此處自定義分辨率、控制檯號碼或其它參數。 su $USER -c '/usr/bin/tightvncserver -depth 16 -geometry 800x600 :1' echo "Starting TightVNC server for $USER " ;; stop) # 終止命令行。此處控制檯號碼與啓動一致。 su $USER -c '/usr/bin/tightvncserver -kill :1' echo "Tightvncserver stopped" ;; *) echo "Usage: /etc/init.d/tightvncserver {start|stop}" exit 1 ;; esac exit 0
sudo chmod 755 /etc/init.d/tightvncserver sudo update-rc.d tightvncserver defaults
#啓動vnc tightvncserver -geometry 800x600 :1 #中止vnc tightvncserver -kill :1 #查看vnc進程 ps ax | grep Xtightvnc | grep -v grep
--------------------------------------------------------------------android
下面文章分兩部分來寫,前一部分是安裝配置vnc,後一部分簡要的使用;web
一.安裝配置VNCshell
安裝VNC須要使用命令行。若是須要遠程操做安裝VNC,就必須經過SSH登陸到命令行界面。安全
1.安裝
樹莓派命令行:bash
sudo apt-get install tightvncserver
參考部分安裝信息:服務器
lifeccp@raspberrypi:~/webapp/osprey/logs $ sudo apt-get install tightvncserver [sudo] password for lifeccp: Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: xfonts-base Suggested packages: tightvnc-java The following packages will be REMOVED: realvnc-vnc-server The following NEW packages will be installed: tightvncserver xfonts-base upgraded, 2 newly installed, 1 to remove and 188 not upgraded. Need to get 6,736 kB of archives. After this operation, 18.4 MB disk space will be freed. Do you want to continue? [Y/n] Y Get:1 http://mirrordirector.raspbian.org/raspbian/ jessie/main tightvncserver armhf 1.3.9-6.5 [555 kB] Get:2 http://mirrordirector.raspbian.org/raspbian/ jessie/main xfonts-base all 1:1.0.3 [6,181 kB] Fetched 6,736 kB in 17s (378 kB/s) (Reading database ... 121043 files and directories currently installed.) Removing realvnc-vnc-server (5.3.2.22164) ... (gconftool-2:5067): GConf-WARNING **: Client failed to connect to the D-BUS daemon: /usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed. Processing triggers for hicolor-icon-theme (0.13-1) ... Processing triggers for shared-mime-info (1.3-1) ... Processing triggers for gnome-menus (3.13.3-6) ... Processing triggers for desktop-file-utils (0.22-1) ... Processing triggers for mime-support (3.58) ... Processing triggers for man-db (2.7.0.2-5) ... Processing triggers for gconf2 (3.2.6-3) ... Selecting previously unselected package tightvncserver. (Reading database ... 120970 files and directories currently installed.) Preparing to unpack .../tightvncserver_1.3.9-6.5_armhf.deb ... Unpacking tightvncserver (1.3.9-6.5) ... Selecting previously unselected package xfonts-base. Preparing to unpack .../xfonts-base_1%3a1.0.3_all.deb ... Unpacking xfonts-base (1:1.0.3) ... Processing triggers for man-db (2.7.0.2-5) ... Processing triggers for fontconfig (2.11.0-6.3+deb8u1) ... Setting up tightvncserver (1.3.9-6.5) ... update-alternatives: using /usr/bin/tightvncserver to provide /usr/bin/vncserver (vncserver) in auto mode update-alternatives: using /usr/bin/Xtightvnc to provide /usr/bin/Xvnc (Xvnc) in auto mode update-alternatives: using /usr/bin/tightvncpasswd to provide /usr/bin/vncpasswd (vncpasswd) in auto mode Setting up xfonts-base (1:1.0.3) ...
2.密碼設置 app
安裝好以後,這裏須要先使用此命令設置一個VNC密碼:
vncpasswd
參考部分安裝信息:
lifeccp@raspberrypi:~/webapp/osprey/logs $ vncpasswd Using password file /home/lifeccp/.vnc/passwd VNC directory /home/lifeccp/.vnc does not exist, creating. Password: Verify: Would you like to enter a view-only password (y/n)? y Password: Verify:
2.配置開機自動啓動
安裝vic以後,能夠修改成開機啓動;
設置開機啓動,須要在/etc/init.d/中建立一個文件。例如tightvncserver:
(注:啓動腳本的名稱,有和程序名一致的習慣)
sudo vi /etc/init.d/tightvncserver
內容以下:(putty窗口中按右鍵=粘貼)
#!/bin/sh ### BEGIN INIT INFO # Provides: tightvncserver # Required-Start: $local_fs # Required-Stop: $local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/stop tightvncserver ### END INIT INFO # More details see: # http://www.penguintutor.com/linux/tightvnc # http://www.cnblogs.com/haochuang/ ### Customize this entry # Set the USER variable to the name of the user to start tightvncserver under export USER='pi' ### End customization required eval cd ~$USER case "$1" in start) # 啓動命令行。此處自定義分辨率、控制檯號碼或其它參數。 su $USER -c '/usr/bin/tightvncserver -depth 16 -geometry 800x600 :1' echo "Starting TightVNC server for $USER " ;; stop) # 終止命令行。此處控制檯號碼與啓動一致。 su $USER -c '/usr/bin/tightvncserver -kill :1' echo "Tightvncserver stopped" ;; *) echo "Usage: /etc/init.d/tightvncserver {start|stop}" exit 1 ;; esac exit 0
而後給tightvncserver文件加執行權限,並更新開機啓動列表。
sudo chmod 755 /etc/init.d/tightvncserver sudo update-rc.d tightvncserver defaults
二.使用VNC進行遠程鏈接
1.電腦登陸VNC
下載Windows客戶端RealVNC Viewer,參考百度雲盤:
登陸地址輸入「IP地址:控制檯號碼」,0號控制檯可不加號碼。
也可以使用Android版VNC客戶端,下載地址:http://android.d.cn/software/19334.html
打開以後以下:
附:手工啓動與參數(如下用處不大,沒興趣請略過)
使用此命令手工啓動VNC服務器程序:
若是首次啓動,而且不曾使用vncpasswd命令設置密碼,程序會要求設置一個。
開機啓動很方便。若是不是處於重大型安全理由,那麼不推薦手工啓動。
命令行參數說明:
1、控制檯:
一、指定控制檯的號碼。
啓動多個控制檯,能夠提供互不影響的多個桌面環境。(大多數人不用多用戶操做因此沒意義)
能夠不加此參數,tightvncserver會自動尋找從1開始的下一個空閒控制檯。
加上此參數,會強制使用指定的控制檯,若是此控制檯已經啓動則報錯。加此參數可有效防止無心屢次啓動程序(會啓動多個控制檯)白白浪費系統資源。
二、特殊的0號控制檯
0號控制檯就是鏈接真實顯示器真正輸出圖像的那個桌面。
對於VNC客戶端,不輸入端口號登陸,默認就登陸到0號控制檯,方便。
可是由於0號是真正的桌面,因此和開機啓動桌面環境,或者本身用startx命令,都存在囉嗦的衝突。
到頭來是個麻煩。所以自動啓動的配置教程中,一概使用1號控制檯。
2、-geometry 800×600,分辨率。能夠不加。
終止VNC控制檯:
tightvncserver -kill :1
查看正在運行的控制檯列表:
ps ax | grep Xtightvnc | grep -v grep
(本文部份內容摘自:樹莓派實驗室 有根據實踐進行部分調整,也可參考:http://shumeipai.nxez.com/2013/09/04/login-rpi-with-vnc.html)