VNC(Virtual Network Computing)
http://blog.yam.com/iwinblue/article/14961544Step 0:簡介
Step 1:檢查你的系統是否有提供 VNC 工具
Step 2:VNC的設定檔
Step 3:VNC 的 password
Step 4:檢查 VNC 服務是否啟動
Step 5:指定用哪個 XWindow
Step 6:VNC Viewer
Step 7:VNC via Browser
Step 0:簡介
VNC(Virtual Network Computing) 是可以遠端遙控 Linux 桌面的服務.
Step 1:檢查你的系統是否有提供 VNC 工具
[root@unsvr root] # rpm -aq | grep -i vnc
vnc-server-version
vnc-version
如果沒有關係可以到 VNC 的官方網站下載 http://www.realvnc.com
Step 2:VNC的設定檔
VNC的設定檔存放在 /etc/sysconfig/vncservers
[root@unsvr root] # vi /etc/sysconfig/vncservers
--------------------------------------------------------
VNCSERVERS="2:root"
VNCSERVERARGS[2]="-genometry 800*600 -nolisten tcp -nohttpd -localhost"
--------------------------------------------------------
VNCSERVERS="2:root"
上面意思是說,我們要啟動一個 VNC 在 port 5900+2 即 5902 的意思.使用者為 root.
VNCSERVERARGS[2]="-genometry 800*600 -nolisten tcp -nohttpd -localhost"
-genometry 800*600
x-windows的解析度為 800*600
-nolisten tcp -nohttpd
如果你要透過 Browser 來使用 VNC,請移除這設定.
-localhost
如果你只允許local(127.0.0.1) 透過 Browser 來連結 VNC.請加入這設定
Step 3: VNC 的 password
基本上 VNC 的 password 無法使用 /etc/passwd,所以要自己設定.
[root@unsvr root] # vncpasswd
Password:
Verify:
這是為 root 使用者來設定.如果要設定其他使用者請 #su - user 轉換後在設定.
Step 4:檢查 VNC 服務是否啟動
[root@unsvr ~]# service vncserver start
如果要讓每次開機時都能啟動 vnc server,請鍵入下面指令.
[root@unsvr ~]# chkconfig vncserver on
[root@unsvr root]# netstat -tulnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:5802 0.0.0.0:* LISTEN 15287/Xvnc
tcp 0 0 0.0.0.0:5902 0.0.0.0:* LISTEN 15287/Xvnc
tcp 0 0 0.0.0.0:6000 0.0.0.0:* LISTEN 15019/X
說明:
port 5802 是給 Web Browser 使用.
port 5902 是給 VNCViewer 使用.
Step 5:指定用哪個 XWindow
指定用哪個 XWindow 是設定在 $HOME/.vnc/xstartup 裡
---------------------------------------------------------------------------
#!/bin/sh
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
---------------------------------------------------------------------------
預設的 XWindow為 twm如果有需要其他的請設定成下面的 XWindow.
gnome-session & (==> for GNOME)
startkde & (==> for KDE)
Step 6:VNC Viewer
在 Linux 下可以直接使用
[root@unsvr root]#vncviewer
不過 Windows 並沒有安裝,所以需要至 http://www.realvnc.com 下載.
Step 7:VNC via Browser
Windows:
不想下載一堆有的沒有的,可以考慮使用 web browser的方式來連結.不過前提是需要加裝 Java Runtime Environment (JRE) http://www.java.com
在 Windows 底下開 browser,輸入網址,再加上 port number : 5802 就可以透過 Web 方式連結.
Linux:
安裝 java runtime environment
你可以在 java 的安裝目錄下 /usr/jave/plugin/i386/ns7/ 找到 libjavaplugin_oji.so 檔
在 ~/.mozilla/plugins/ 目錄裡做一個符號連結到 libjavaplugin_oji.so,不可以直接複製。
[root@unsvr root]# cd ~/.mozilla/plugins/
[root@unsvr root]# ln -s /usr/java/jre1.5.0_04/plugin/i386/ns7/libjavaplugin_oji.so
可以參考 Mozilla 的網站
http://wiki.moztw.org/index.php/Plugins_%E7%9A%84%E5%AE%89%E8%A3%9D
另一:
新一篇: linux 开机启动 oracle
下载地址:http://www.realvnc.com/download.html
参考资料:
http://liy.slat.org/study/tips/vnc.html
http://www.realvnc.com
< 第一方法>
遠端控制一直是個理想的工作目標,你不但可以在本機使用電腦,在離開之後,還可以使用網路使用遠端的功能來繼續你未完的工作。
現在市面上最流行的 Symantec PcAnywhere 也是這種功能,但是這是要花 錢的,而且還蠻貴的,當然,它還包含了一些其它的進階功能。然而,如果你只 需要單純只要可以遠端控制你的電腦的話,當然就不用如此殺雞用牛刀了,VNC (Virtual Network Computing) 正是我們所需要的軟體,他不但是完全 Free 的,你可以拿到他的可執行檔,或是如果你的興趣的話,也可以找到他的 Source 供你研究,最重要的一點,他的檔案很小,只需要一片磁片就夠了。
這篇文章在 RedHat 8 、RedHat 9 和 Fedora 1 上測過,可以正常執行。
1. 首先,我們們要先下載 VNC 來安裝,假設我們現在裝在自己的家目錄裡 的 VNC/vncgo 目錄裡。
# cd ~
# wget http://www.realvnc.com/dist/vnc-3.3.7-x86_linux.tar.gz
# tar -zxvf vnc-3.3.7-x86_linux.tar.gz
# mv vnc-3.3.7-x86_linux vnc
# cd vnc
# mkdir -p ~/VNC/vncgo
# ./vncinstall ~/VNC/vncgo
2. 接著,我們就要設定環境變數,因為 VNC 在啟動的時候,會去找相關的檔案,所以一定要先指定 PATH 的變數。如果你是 root,你可以把下面的三行指令寫到 /etc/profile 裡面。
# PATH="$PATH":~/VNC/vncgo
# export $PATH
# echo $PATH
/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/UserHomeDir/VNC/vncgo
3. 以上就安裝完成 VNC Server ,現在就開始來玩玩吧!先開啟第一次,讓他
產生必要的檔案,如果是第一次執行,就會要你輸入登入的密碼才行!
# vncserver
4. 然後關閉 VNC
# vncserver -kill :1
5. 修改 X 的設定, 這樣你的遠端桌面才會美美的!
# cd ~/.vnc/xstartup
# vi xstartup
________________________________________________________________
#!/bin/sh
#下面都註解起來
#輸入下面這一行
/etc/X11/xinit/Xclients
#[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
#xsetroot -solid grey
#xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#twm &
:______________________________________________________________
6. 最後, 就開始 VNC 吧
# vncserver
7. 遠端控制
執行 vncviewer ,使用 VNC Viewer 來看,輸入IP:num(IP 是主機的位置,num 是 vnc 的啟動項目,開啟 vnc 服務時會有提示)
< 第二种方法>
(1)tar -xvf vnc-4.0-x86.tar
(2)cd vnc-4.0-x86
(3) ./vncinstall /usr/local/bin
(4) mkdir -P /usr/local/vnc/classes
(5) cp java/* /usr/local/vnc/classes
(6) vncserver 启动,可以正常运行了 可以通过 netstat -an | grep 01查看端口是否正常启动,如果要看到桌面可按如下方法:
vi ~/.vnc/xstartup文件中加入如下两句:
unset SESSION_MANAGER
exec /etc/X11/xinit/xinitrc 如有/etc/X11/xinit/Xclients 此句注掉
另二:
Vnc Server 4.1.2 建置on CentOS 5
adj 發表於: 2007-11-29 21:57 來源: ADJ網路控股集團
Check what's installed
First check if you already have them installed on your system, open a terminal and type:
CODE:
$ rpm -qa|grep vnc
vnc-server-4.1.1-36
vnc-4.1.1-36
If you get an output something like this then you're all ready, if not you need to install them via yum.
Add a user(s)
Next we need to add at least 1 VNC user, open the file /etc/sysconfig/vncservers as root and add the information shown:
CODE:
$ vi /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# 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
#
.
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
# Use "-nohttpd" to prevent web-based VNC clients connecting.
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.
VNCSERVERS="1:bobpeers"
VNCSERVERARGS[1]="-geometry 1024x768 -depth 16"
The important part is the VNCSERVERS="1:bobpeers", this sets up a users for the vnc server, you can add as many as you like here. The VNCSERVERARGS[1] line refers to the arguments for user 1, in this case the only user. Geometry sets the size and depth sets the colour depth, you can adjust these to suit your preferences but in my case the client machine has a resolution of 1024x768 and the depth 16 makes the connection a bit faster since the less information that needs to be sent the more responsive the session will feel.
Knowing which port to use
It's also important to note the session number user as this will tell us which port vncserver will listen on. Remember the Gnome Remote Desktop asked us to use computername:0 as the connection string, the number needs to be added to 5900 to get the listening port. In this case we need to use port 5901 since we are using session 1. In the same way we could use any number, for example:
CODE:
VNCSERVERS="2000:bobpeers"
VNCSERVERARGS[2000]="-geometry 1024x768 -depth 16"
In this case we need to use port 5900+2000 so port 7900.
Setting a password
To add some security we need to add a password that must be given before a connection can be established, open a terminal and type:
CODE:
$ vncpasswd
Password:
Verify:
This creates a hidden folder called .vnc in your home folder containing the password file.
Starting the server and startup options
To start the server we type the command 'vncserver' and the session you wish to start (if you have set up more than 1 entry in the /etc/sysconfig/vncservers file:
CODE:
$ vncserver :1
Starting VNC server: 1:bobpeers
New 'linux.bobpeers:1 (bobpeers)' desktop is linux.bobpeers:1
Starting applications specified in /home/bobuser/.vnc/xstartup
Log file is /home/bobuser/.vnc/linux.bobpeers:1.log
[ OK ]
Now the server is started and a user could connect, however they will get a plain grey desktop by default as the connection will not cause a new session of X to start by default, to fix this we need to edit the startup script in the .vnc folder in your home directory.
CODE:
$ vi ~/.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 &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
As the file says make sure the two lines at the top are uncommented by removing the leading # sign. Next we need to restart vncserver to pick up the changed we just made. To restart the vncserver we need to kill the process and start a new one as root:
CODE:
$ vncserver -kill :1
Killing Xvnc process ID 13728
$ vncserver :1
Starting VNC server: 1:bobpeers
New 'linux.bobpeers:1 (bobpeers)' desktop is linux.bobpeers:1
Starting applications specified in /home/bobuser/.vnc/xstartup
Log file is /home/bobuser/.vnc/linux.bobpeers:1.log
[ OK ]
PS: 測試時發現 $Home/.vnc/xstartup 需要有 +x 的權限...要不然登入遠端主機時會看不到GDM的畫面...可能要注意一下
相關文章來至:
http://bobpeers.com/linux/vnc.php
另二:
Configuring the VNC server/viewer in Linux.
Page contents
Overview of VNC
Gnome Remote Desktop (vino)
vncserver and viewer
Allowing remote connections
Overview of VNC
VNC, or Virtual Networked Computing, is a way of controlling a remote computer just as though you are sitting in front of it. In the Windows world it is also known as remote desktop but it's normally referred to as VNC in the Linux world. All that happens is that you connect using a VNC client to a remote computer running the VNC server, then an image of the remote desktop is transmitted to your local computer and you can see and control the desktop just as though you are there since all keyboard and mouse commands are sent from your client machine to the server.
Gnome Remote Desktop
If you are running the Gnome desktop on Fedora Core then you already have a VNC server built in. Click on the Fedora icon > Desktop > Preferences > Remote Desktop to open the dialog shown.
The screen is pretty self explanatory but basically when set up this way another computer can connect to your computer using the command listed on the dialog. There are a few important things to note, you must open port 5900 on the server for this to work since by default the Gnome Remote Desktop (called vino) listens on this port, also the person connecting will see the same session that you are currently logged in as. This means that any programs you have open will also be visible to the client, of course this is very useful if you are helping someone remotely.
A more flexible way to use VNC is to install the VNC server and client software via yum, these are rpm's based on RealVNC.
vncserver and vncviewer
Check what's installed
First check if you already have them installed on your system, open a terminal and type:
$ rpm -qa|grep vnc
vnc-server-4.1.1-36
vnc-4.1.1-36
If you get an output something like this then you're all ready, if not you need to install them via yum.
Add a user(s)
Next we need to add at least 1 VNC user, open the file /etc/sysconfig/vncservers as root and add the information shown:
$ vi /etc/sysconfig/vncservers
# The VNCSERVERS variable is a list of display:user pairs.
#
# Uncomment the lines below to start a VNC server on display :2
# 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
# .
# Use "-nolisten tcp" to prevent X connections to your VNC server via TCP.
# Use "-nohttpd" to prevent web-based VNC clients connecting.
# Use "-localhost" to prevent remote VNC clients connecting except when
# doing so through a secure tunnel. See the "-via" option in the
# `man vncviewer' manual page.
VNCSERVERS="1:bobpeers"
VNCSERVERARGS[1]="-geometry 1024x768 -depth 16"
The important part is the VNCSERVERS="1:bobpeers", this sets up a users for the vnc server, you can add as many as you like here. The VNCSERVERARGS[1] line refers to the arguments for user 1, in this case the only user. Geometry sets the size and depth sets the colour depth, you can adjust these to suit your preferences but in my case the client machine has a resolution of 1024x768 and the depth 16 makes the connection a bit faster since the less information that needs to be sent the more responsive the session will feel.
Knowing which port to use
It's also important to note the session number user as this will tell us which port vncserver will listen on. Remember the Gnome Remote Desktop asked us to use computername:0 as the connection string, the number needs to be added to 5900 to get the listening port. In this case we need to use port 5901 since we are using session 1. In the same way we could use any number, for example:
VNCSERVERS="2000:bobpeers"
VNCSERVERARGS[2000]="-geometry 1024x768 -depth 16"
In this case we need to use port 5900+2000 so port 7900.
Setting a password
To add some security we need to add a password that must be given before a connection can be established, open a terminal and type:
$ vncpasswd
Password:
Verify:
This creates a hidden folder called .vnc in your home folder containing the password file.
Starting the server and startup options
To start the server we type the command 'vncserver' and the session you wish to start (if you have set up more than 1 entry in the /etc/sysconfig/vncservers file:
$ vncserver :1
Starting VNC server: 1:bobpeers
New 'linux.bobpeers:1 (bobpeers)' desktop is linux.bobpeers:1
Starting applications specified in /home/bobuser/.vnc/xstartup
Log file is /home/bobuser/.vnc/linux.bobpeers:1.log
[ OK ]
Now the server is started and a user could connect, however they will get a plain grey desktop by default as the connection will not cause a new session of X to start by default, to fix this we need to edit the startup script in the .vnc folder in your home directory.
$ vi ~/.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 &
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
twm &
As the file says make sure the two lines at the top are uncommented by removing the leading # sign. Next we need to restart vncserver to pick up the changed we just made. To restart the vncserver we need to kill the process and start a new one as root:
$ vncserver -kill :1
Killing Xvnc process ID 13728
$ vncserver :1
Starting VNC server: 1:bobpeers
New 'linux.bobpeers:1 (bobpeers)' desktop is linux.bobpeers:1
Starting applications specified in /home/bobuser/.vnc/xstartup
Log file is /home/bobuser/.vnc/linux.bobpeers:1.log
[ OK ]
Using vncviewer
To start the viewer type:
$ vncviewer localhost:5901
This open a dialog as shown for us to enter our password we set earlier, enter the password and you should now see a copy of your desktop. Note that unlike the Gnome Remote Desktop this has started a new session of X so any applications open on the host machine are not visible to the new session, it's basically a whole new logon running at the same time.
If you just type 'vncviewer' at the prompt then you will asked for the host to connect to, then you can type localhost:5901 for example. Remember to use the correct port number when connecting, if you set your VNCSERVERS to be 2000:myname then you would need to connect on localhost:7900.
Stopping the vncserver
There are two ways to stop the server, either as root:
$ /sbin/service vncserver stop
Shutting down VNC server: 1:bobpeers [ OK ]
or you can explicitly kill a particular session without being root:
$ vncserver -kill :1
Killing Xvnc process ID 13728
Just replace the 1 with the vnc session you wish to stop.
Allowing remote connections
So far we have only connected to our own computer using localhost so we have not needed to open any ports in the firewall, however if we want to allow remote connection we will have to do the following. This can either be done from the command line or using system-config-security if you have it installed.
Using system-config-security to opens ports.
First we'll look into the GUI system-config-security. Go to the Fedora start menu > Desktop > Administration > Security Level and Firewall, then type your root password when prompted to see this:
Click on other ports at the bottom and enter the port you wish to open, 5901 in my case, select tcp, then click OK and OK again to save your settings. That's all there is to it, but remember to close the port again when you are finished.
Editing the iptables manually to opens ports.
To do the same from the command line add the line in bold to the file /etc/sysconfig/iptables while logged in as root:
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
Finally we need to restart the iptables service to reload the changes.
$ sudo /sbin/service iptables restart
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT: filter [ OK ]
Unloading iptables modules: [ OK ]
Applying iptables firewall rules: [ OK ]
Loading additional iptables modules: ip_conntrack_netbios_n[ OK ]
Connecting from the remote machine.
Now from the remote client computer start up vncviewer but this time use the IP address of the host computer followed by the port number. So on my home network this might be:
$ vncviewer 192.168.1.105:5901