您的位置:首页 > 其它

Windows远程远程连接RHEL5桌面配置

2011-02-28 00:13 435 查看








什么是VNC? [/b]
VNC是虚拟网络计算Virtual Network Computing的缩写. 他是一个远程控制程序,允许用户在因特网的任何地方使用简单的程序来和一个特定的计算机(服务器)进行交互. 两个交互的计算机不一定非得是同一类型,所以你可以在家里的运行windows的PC上来察看办公室里运行LINUX的机器。VNC可以自由获取并且有上百万的人在使用,他们来自工业、学术和个人应用等不同层面. 更多的信息请访问 http://www.realvnc.com/ 我的系统中已经有这个软件了吗?
键入下面的命令来检查vnc客户端和服务器是否已经安装在你的系统中:
[tchung@tchung101 tchung]$ rpm -q vnc vnc-server
vnc-4.0-0.beta4.3.2
vnc-server-4.0-0.beta4.3.2
[tchung@tchung101 tchung]$
要把vnc配置成一项系统服务,把你的用户名称加入到下面的配置文件中:
[tchung@tchung101 tchung]$ sudo 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
# URL:http://www.uk.research.att.com/vnc/sshvnc.html

# VNCSERVERS="1:myusername"
VNCSERVERS="1:tchung"
VNCSERVERARGS[1]="-geometry 1024x768"
在启动vnc服务之前,让我们用vncpasswd这个命令来创建一个vnc的口令
注意这将同时在你的home目录下,创建一个隐藏的目录.vnc,其中有一个文件passwd保存着你的vnc口令.
[tchung@tchung101 tchung]$ vncpasswd
Password:
Verify:
[tchung@tchung101 tchung]$ ls -d .vnc
.vnc
[tchung@tchung101 tchung]$ ls .vnc
passwd
[tchung@tchung101 tchung]$
现在来启动vnc服务.
[tchung@tchung101 tchung]$ sudo /sbin/service vncserver start
Starting VNC server: 1:tchung [ OK ]
[tchung@tchung101 tchung]$
察看一下.vnc这个目录的内容,应该类似于下面的东西.
[tchung@tchung101 tchung]$ cd .vnc
[tchung@tchung101 .vnc]$ ls
passwd tchung101:1.log tchung101:1.pid xstartup
[tchung@tchung101 .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 &
因为我们已经修改了启动脚本,现在来重新启动vncserver.
[tchung@tchung101 tchung]$ sudo /sbin/service vncserver restart
Shutting down VNC server: 1:tchung [ OK ]
Starting VNC server: 1:tchung [ OK ]
[tchung@tchung101 tchung]$
那么怎样来连接到vncserver? 照下面使用客户端的vncviewer命令.
[tchung@tchung101 tchung]$ vncviewer localhost:1
输入你的vnc口令,看一下结果
更新:
在使用防火墙的情况下来连接到一个远程系统,需要打开端口5901.
加入以下红色的部分,然后重启iptables服务。
[tchung@tchung101 tchung]$ sudo vi /etc/sysconfig/iptables
# Firewall configuration written by redhat-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0]
:FORWARD ACCEPT [0]
:OUTPUT ACCEPT [0]
:RH-Firewall-1-INPUT - [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 -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 5901 -j ACCEPT[/b]
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
或者:
  这句话的含义是,允许其它机器访问本机的5900到5903端口,这样,display:1, display:2, display:3的用户就可以连接到本机。
[tchung@tchung101 tchung]$ 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 ]
[tchung@tchung101 tchung]$
Forrest Taylor 提供的TIP
让vncserver接受两个不同的用户:
VNCSERVERS="1:tchung 2:thomasc"
当然你要为两个用户分别运行vncpasswd来设置口令. 并且在你的防火墙修改中,你应该明白VNC使用端口5901给连接1用,如果象上面一样要支持两个用户,应同时打开5901和5902.
---------------------------------------------------------------------------------------------------------

更改别的登陆桌面

  不过……这个桌面怎么这么丑?!

  原来vncserver默认使用的窗口管理器是twm,这是一个很简陋的窗口管理器,你可以把你的桌面改成GNOME或KDE。
  方法是,进入你自己的home目录,然后编辑这个文件:.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 &
  gnome-session &
  你可以把像上面这样把"twm &"这一行注释掉,然后在下面加入一行"gnome-session &",或者是"startkde &",分别启动GNOME桌面和KDE桌面。

  如果server重启了,那你就需要重新运行一次vncserver命令来启动VNC server,这很麻烦。有没有更好的方法呢?

  有!我们可以把VNC server启动成后台服务。执行如下步骤:

  首先要允许VNC server在系统启动过程中被启动。这可以通过“系统设置——>服务器设置——>服务”菜单来配置,把vncserver一项选上就可以了。

  如果使用命令行的话,以root身份运行以下两条命令:

  cd /etc/rc5.d

  mv K35vncserver S35vncserver

  然后编辑/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

# <URL:http://www.uk.research.att.com/vnc/sshvnc.html>.

VNCSERVERS="1:user1 2:user2 3:user3"

VNCSERVERARGS[1]="-geometry 1024x768"

VNCSERVERARGS[2]="-geometry 1024x768"

VNCSERVERARGS[3]="-geometry 800x600 -alwaysshared -depth 24"
解释一下这个文件:

  VNCSERVERS这一行是配置在系统启动时启动几个VNC server,上面的例子里运行了三个VNC server,其中user1在display :1,user2在display :2,user3在display :3。

  VNCSERVERARGS这三行,分别为VNC server 1, 2, 3配置启动参数,上面的例子里对user1和user2使用屏幕分辨率1024x768,对user3使用800x600。 -alwaysshared代表允许多用户同时登录 -depth代为色深,参数有8,16,24,32。

  其它支持的参数请使用“man vncserver”命令查询。

  编辑好这个文件后,保存,然后以root身份运行:

  /sbin/service vncserver start

  这样user1, user2, user3的vncserver就启动了。

  以后每次系统重启时,都会自动启动这三个用户的vncserver。

  注意:上面三个用户必须已经使用vncpasswd命令设置过vnc密码,不然他的vncserver启动会失败!

如果直接使用VNCviewer来进行访问,有两点不利因素:
1.口令传输是明文,很容易被侦听到.
2.防火墙需要打开59xx端口,这在通常的单位里是不可能的.
幸运的是,我们有ssh这个强大的工具,象X11 Forwarding(另文论述),我们可以使用ssh隧道来保护通讯过程,下面就进行简单介绍.
假设VNCserver运行在服务器 myserver (ip地址为:192.168.x.x)的屏幕1,也就是侦听 192.168.x.x:5901, 用户名为foo
情形一: VNC客户端为Linux
这种情形很简单,一般的Linux发行版本里面都默认安装了ssh套件.
1. 用ssh登录到服务器
ssh -L 5901:localhost:5901 -l foo myserver
或者直接用ip地址
ssh -L 5901:localhost:5901 -l foo 192.168.x.x
2. 在本机的另外开的终端上,运行VNCviewer (或其它的类似工具)
VNCviewer localhost:1
情形二: VNC客户端为windows
1. 下载一个ssh客户端,个人推荐putty
2. 运行putty,输入服务器的ip地址,输入一个名字,这里myserver作为session的名字,按save保存。
3. 单击对话框左边的tunnels来选择相关设置,在source port里输入5901,在Destination里输入localhost:5901,按Add添加
4. 单击左边session,回到session设置,按save重新保存。按open并登录到服务器。
5. 运行VNC-viewer (如果没有,到这里下载http://www.realVNC.com/download.html,只要一个 exe的文件就行),在Server里输入localhost:1,见附图三, 输入口令后一个Linux的桌面就会出现在windows里,并且是非常安全的,Cool 能玩到这步骤的都是我崇拜的对象。哈
_________________________________________________________________
在系统登录前就能远程登陆VNC

在系统启动的时候启动vnc远程桌面共享

[本人已经在RHEL5.3上测试过可以用的,willor]

使用VNC的最简单的方法是通过gnome下的VINO,就是system->Preference->Remote Desktop,但是这种方法存在一个问题就是当系统重启后,需要跑到机器上登录一个session才能进行远程共享。

ubuntuforums.org中有很多vnc的resumable session的方法,但都是新启动一个session。下面的方法能够达到这样的效果:

如果有当前session,则显示当前的session,如果当前没有session,显示gdm登录界面,这样系统重新启动后可以远程登录一个session,并一直保持该session。

如果你希望达到这个效果的话可以这么做,下面的过程是在dapper和edgy下,feisty also测试过, RHEL 5.3 also tested, and works.

1. 安装vnc4server

代码:
apt-get install vnc4server
2. 设置共享桌面密码:
代码:
sudo vncpasswd
会在当前用户的.vnc目录下生成passwd文件,记下该文件的路径

3. 修改/etc/X11/xorg.conf,修改前记得备份

在Section "Module"下增加一行
代码:
Load "vnc"
在Section "Screen"下增加一行vnc口令文件位置,记得用你自己的路径替换
代码:
Option "PasswordFile" "/home/user/.vnc/passwd"
4. 如果你原来打开了remote desktop的共享,记得关闭。

5. alt-ctrl-backspace测试一下
from:http://forum.ubuntu.org.cn/viewtopic.php?t=48870

http://www.realvnc.com/products/free/4.0/x0.html

Section "Module"

...

Load "vnc"

EndSection

...Section "Screen"

...Option "passwordFile" "/root/.vnc/passwd"

EndSection

_________________________________________________________________
或者:http://tech.techweb.com.cn/thread-314071-1-1.html [willor未测试,但有人报告可以]
不需要登录。

1 确保vncserver已经安装

2 用root身份 修改 /etc/sysconfig/vncservers , 增加一行 VNCSERVERS="1:yourname"

其中,yourname 是vnc图形环境的用户名,是linux 下的真实用户

3 切换到 启动vnc的用户 yourname ,运行 vncpasswd 修改密码并确认

4 用root用户,运行 /etc/init.d/vncserver restart

4 修改 yourname home目录下的 .vnc/xstartup 文件,把 最后一行的 twm & 注释掉 (行首加 #",

增加一行 gnome-session &

5 用root 身份登录,运行 /etc/init.d/vncserver restart 启动vnc

6 用winvnc 连到这台linux 机器,server 填入 yourip:5901 ,注意,端口是5901 ,密码窗口出现后,即可

输入正确的密码登录进去,即是gnome界面。

7 最好在服务控制 里面,自动启动vncserver

_________________________________________________________________
或者http://linux.chinaunix.net/bbs/thread-1062282-1-1.html [willor未测试]
编辑/etc/sysconfig/vncservers

VNCSERVERS="1:user1"

ARGS="-geometry 800x600 -alwaysshared "

在ARGS 中修改"800x600"来适应自己的X桌面实际参数配置。可以在这里添加任何其他VNC服务器参数配置。在VNCSERVERS中修改 user1 为你希望运行VNC桌面的用户。VNCSERVERS中的1表示VNC以桌面1运行,如果希望添加其他的桌面,可以修改配置如下:

VNCSERVERS="1:user1 2:user2 3:user3"
本文转自http://hi.baidu.com/willor/blog/item/a585ba446ad5062fcffca3ac.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: