使用VNC實現LINUX與windows的相互遠端控制

來源:互聯網
上載者:User


使用VNC實現LINUX與windows的相互遠端控制 1、確認linux系統是否安裝VNC預設情況下,Red Hat Enterprise Linux安裝程式會將VNC服務安裝在系統上。[root@localhost ~]# rpm -qa|grep vncvnc-server-4.1.2-9.el5  www.2cto.com  [root@localhost ~]#2、[root@localhost ~]# service vncserver start 第一次啟動時會提示輸入密碼,這個密碼是用戶端登入這個VNC伺服器時需要提供的驗證密碼。vncserver服務啟動後會在目前使用者的宿主目錄中產生.vnc目錄,如下所示:
 [root@localhost ~]# ls -a.                .cshrc    .gnome2             .metacity   .vnc..               Desktop   .gnome2_private     .mozilla    .Xauthorityanaconda-ks.cfg  .dmrc     .gstreamer-0.10     .nautilus   .xsession-errors.bash_history    .eggcups  .gtkrc-1.2-gnome2   .redhat.bash_logout     .gconf    .ICEauthority       .tcshrc.bash_profile    .gconfd   install.log         .Trash.bashrc          .gnome    install.log.syslog  .twmjtHtnR[root@localhost ~]#[root@localhost .vnc]# lslocalhost.localdomain:1.log  localhost.localdomain:1.pid  passwd  xstartup[root@localhost .vnc]#因為服務是第一次執行,需要輸入密碼,這個密碼被加密儲存在使用者主目錄下的.vnc子目錄(/root/.vnc/passwd)中;同時在使用者主目錄下的.vnc子目錄中為使用者自動建立xstartup設定檔(/root/.vnc/xstartup),在每次啟動VND服務時,都會讀取該檔案中的配置資訊。:/root/.vnc/目錄下還有一個“testdb:1.pid”檔案,這個檔案記錄著啟動VNC後對應後天作業系統的進程號,用於停止VNC服務時準確定位進程號。
 3.VNC服務使用的連接埠號碼與案頭號的關係VNC服務使用的連接埠號碼與案頭號相關,VNC使用TCP連接埠從5900開始,對應關係如下案頭號為“1”  ---- 連接埠號碼為5901案頭號為“2”  ---- 連接埠號碼為5902案頭號為“3”  ---- 連接埠號碼為5903……基於Java的VNC客戶程式Web服務TCP連接埠從5800開始,也是與案頭號相關,對應關係如下案頭號為“1”  ---- 連接埠號碼為5801案頭號為“2”  ---- 連接埠號碼為5802案頭號為“3”  ---- 連接埠號碼為5803
 4、要想登入後linux的圖形介面,需要修改設定檔:[root@testdb ~]# vi /root/.vnc/xstartup#!/bin/sh  www.2cto.com  # Uncomment the following two lines for normal desktop:unset SESSION_MANAGERexec /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 &
 5:重新啟動vncserver服務的方法:[root@testdb ~]# vncserver -kill :1[root@testdb ~]# vncserver :1 在IP為192.168.1.234的linux主機中配置VNC伺服器:[root@localhost ~]# rpm -qa|grep vncvnc-server-4.1.2-9.el5[root@localhost ~]# vncserver :1You will require a password to access your desktops.Password:Verify:                         這個密碼可以通過vncpasswd來修改           xauth:  creating new authority file /root/.XauthorityNew 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1Creating default startup script /root/.vnc/xstartupStarting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/localhost.localdomain:1.log[root@localhost ~]# ls -a.                .bashrc   .gconfd            .ICEauthority       .tcshrc..               .cshrc    .gnome             install.log         .Trashanaconda-ks.cfg  Desktop   .gnome2            install.log.syslog  .vnc.bash_history    .dmrc     .gnome2_private    .metacity           .Xauthority.bash_logout     .eggcups  .gstreamer-0.10    .nautilus           .xsession-errors.bash_profile    .gconf    .gtkrc-1.2-gnome2  .redhat[root@localhost ~]# cd .vnc/  www.2cto.com  [root@localhost .vnc]# lslocalhost.localdomain:1.log  localhost.localdomain:1.pid  passwd  xstartup[root@localhost .vnc]# lltotal 16-rw-r--r-- 1 root root 556 May 19 10:28 localhost.localdomain:1.log-rw-r--r-- 1 root root   5 May 19 10:28 localhost.localdomain:1.pid-rw------- 1 root root   8 May 19 10:28 passwd-rwxr-xr-x 1 root root 334 May 19 10:28 xstartup[root@localhost .vnc]#[root@localhost .vnc]# netstat -ntpl|grep vnctcp        0      0 0.0.0.0:5801                0.0.0.0:*                   LISTEN      3480/Xvnc          tcp        0      0 0.0.0.0:5901                0.0.0.0:*                   LISTEN      3480/Xvnc          tcp        0      0 0.0.0.0:6001                0.0.0.0:*                   LISTEN      3480/Xvnc          tcp        0      0 :::6001                     :::*                        LISTEN      3480/Xvnc     別忘了把防火牆關閉。   在windows主機上安裝VNC用戶端:安裝企業版VNC(含有伺服器端和用戶端)這個時候就可以使用用戶端vnc viewer遠程linux的VNC伺服器了,現在只能使用linux的字元介面。注意訪問的是:192.168.1.234:1如果想用圖形介面,還需要修改一個設定檔:[root@localhost .vnc]# vi xstartup#!/bin/sh# Uncomment the following two lines for normal desktop:# unset SESSION_MANAGER  www.2cto.com  # 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 &
 把上面兩行的注釋去掉後,重啟VNCSERVER[root@localhost .vnc]# vncserver -kill :1Killing Xvnc process ID 3480[root@localhost .vnc]# vncserver :1New 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/localhost.localdomain:1.log[root@localhost .vnc]#這時再使用xp上的vnc viewer就可以遠程linux圖形介面了。第二種方法是使用Web瀏覽器(如Firefox,IE,Safari)登陸測試,操作流程如下地址欄輸入http://192.168.1.234:5801/ --> 出現VNC viewer for Java(此工具是使用Java編寫的VNC用戶端程式)介面,同時跳出VNC viewer對話方塊,在Server處輸入“192.168.1.234:1”點擊“OK” --> Password輸入登陸密碼 --> 點擊“OK”登陸到X-Window圖形案頭環境 --> 測試成功(註:VNC viewer for Java需要JRE支援,如果頁面無法顯示,表示沒有安裝JRE,可以到http://java.sun.com/javase/downloads/index_jdk5.jsp下載最新的JRE,然後在客戶機上進行安裝)。 #vi  /etc/sysconfig/vncservers,以下是檔案內容:# The VNCSERVERS variable is a list of display:user pairs.## Uncomment the line below to start a VNC server on display : 1# as my ’myusername’ (adjust this to your own). You will also# need to set a VNC password ; run ’man vncpasswd’ to see how# to do that.## DO NOT RUN THIS SERVICE if your local area network is# untrusted! For a secure way of using VNC , see# .  www.2cto.com  VNCSERVERS= “ 1:user1 2:user2 3:user3 “VNCSERVERARGS [ 1 ] = “ -geometry 1024×768 “VNCSERVERARGS [ 2 ] = “ -geometry 1024×768 “VNCSERVERARGS [ 3 ] = “ -geometry 800×600 “
 解釋一下這個檔案:VNCSERVERS這一行是配置在系統啟動時啟動幾個VNC server,上面的例子裡運行了三個VNC server,其中user1在display :1,user2在display :2,user3在display :3。VNCSERVERARGS這三行,分別為VNC server 1, 2, 3配置啟動參數,上面的例子裡對user1和user2使用螢幕解析度1024×768,對user3使用800×600其它支援的參數請使用“man vncserver”命令查詢。編輯好這個檔案後,儲存,然後以root身份運行:/sbin/service vncserver start這樣user1, user2, user3的vncserver就啟動了。以後每次系統重啟時,都會自動啟動這三個使用者的vncserver。注意:上面三個使用者必須已經使用vncpasswd命令設定過vnc密碼,不然他的vncserver啟動會失敗!
 [root@localhost ~]# service vncserver restartShutting down VNC server: 1:root 2:lisi 3:tom              [  OK  ]Starting VNC server: 1:rootNew 'localhost.localdomain:1 (root)' desktop is localhost.localdomain:1Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/localhost.localdomain:1.log2:lisiNew 'localhost.localdomain:2 (lisi)' desktop is localhost.localdomain:2Starting applications specified in /home/lisi/.vnc/xstartupLog file is /home/lisi/.vnc/localhost.localdomain:2.log3:tomNew 'localhost.localdomain:3 (tom)' desktop is localhost.localdomain:3Starting applications specified in /home/tom/.vnc/xstartupLog file is /home/tom/.vnc/localhost.localdomain:3.log                         www.2cto.com                         [  OK  ][root@localhost ~]# 使用VNC View遠端存取Linux,總是沒有辦法切換出SCIMIME,研究了很久,終於讓我找到瞭解決 方法 。1)修改.vnc/xstartup檔案,在最後一行加入:scim -d,意思為開啟SCIMIME2)使用VNC View訪問Linux系統以後,修改scimIME的快速鍵,因為預設開啟IME的快速鍵為ctrl space,與本地機器上切換IME的快速鍵沖 突,系統 會先接收到本地的命令,所以沒辦法使用預設快速鍵開啟IME。將開啟SCIMIME的快速鍵修改為Ctrl Alt Space。在windows上安裝vnc伺服器,使用vnc4.0.rar這個軟體,最好不要使用企業版的。安裝時可以設定一個遠程時的驗證密碼,安裝好後使用linux下的vnc viewer遠程就可以了,只需要輸入windows的IP就可以了  作者 dnfonbbs

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.