远程桌面--tiger VNC
本文详细介绍了如何在Fedora 12中配置VNC Server,包括配置自动启动以及启动参数。
安装VNC Server软件
Linux上面的VNC Server软件有很多,因为本人喜欢Tiger VNC的客户端,所以这里也采用Tiger VNC Server。运行如下命令进行安装sudo yum install tigervnc-server
配置VNC Server
假定我们的目标是以用户user1来启动VNC Server,显示端口是1(也就是5901),分辨率1152x864
配置用户user1的VNC密码和参数
以用户user1登录,运行vncpasswd 即可设置密码然后,编辑/home/user1/.vnc/xstartup(如果不存在的话,可以手动创建一个,并给予可执行权限),内容如下:
-
view plaincopy to clipboardprint?
-
#!/bin/sh
-
vncconfig -iconic &
-
unset SESSION_MANAGER
-
unset DBUS_SESSION_BUS_ADDRESS
-
OS=`uname -s`
-
if [ $OS = 'Linux' ]; then
-
case "$WINDOWMANAGER" in
-
*gnome*)
-
if [ -e /etc/SuSE-release ]; then
-
PATH=$PATH:/opt/gnome/bin
-
export PATH
-
fi ;;
-
esac
-
fi
-
if [ -x /etc/X11/xinit/xinitrc ]; then
-
exec /etc/X11/xinit/xinitrc
-
fi
-
if [ -f /etc/X11/xinit/xinitrc ]; then
-
exec sh /etc/X11/xinit/xinitrc
-
fi
-
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
-
xsetroot -solid grey
-
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
-
#twm &
-
#!/bin/sh
-
vncconfig -iconic &
-
unset SESSION_MANAGER
-
unset DBUS_SESSION_BUS_ADDRESS
-
OS=`uname -s`
-
if [ $OS = 'Linux' ]; then
-
case "$WINDOWMANAGER" in
-
*gnome*)
-
if [ -e /etc/SuSE-release ]; then
-
PATH=$PATH:/opt/gnome/bin
-
export PATH
-
fi ;;
-
esac
-
fi
-
if [ -x /etc/X11/xinit/xinitrc ]; then
-
exec /etc/X11/xinit/xinitrc
-
fi
-
if [ -f /etc/X11/xinit/xinitrc ]; then
-
exec sh /etc/X11/xinit/xinitrc
-
fi
-
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
-
xsetroot -solid grey
-
xterm -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
-
#twm &
配置防火墙以及SELinux
运行system-config-firewall启动防火墙配置界面,在Other Ports里面添加端口5901,协议选择tcp.如果启用了SELinux的话,需要运行sudo chcon -t unconfined_exec_t /usr/bin/vncserver 改变vncserver的Security Context,否则在使用VCN连接的时候会碰到很多问题,比如点击桌面的图标没有反应,程序不能被启动等等。
配置VNC Server自动启动
编辑/etc/sysconfig/vncservers,内容如下:
view
plaincopy to clipboardprint?
VNCSERVERS="1:user1"
VNCSERVERARGS[1]="-geometry 1152x864"
VNCSERVERS="1:user1"
VNCSERVERARGS[1]="-geometry
1152x864"
然后运行sudo
chkconfig --level 345 vncserver on ,让VNC
Server随系统自动启动最后,运行sudo
/etc/init.d/vncserver start 来启动VNC
Server
NOTE: -geometry 1152x864 is used to specify the resolution(分辨率),if the value is not correct, you will can't see the screen comfortably! the correct value is as same as the resolution setting of the remote machine!,for example, 1440x900
the value should be set via "configure display setting" in remote machine!
测试连接
使用VNC客户端连接<fedora12_ip>:1 ,使用上面设置的密码。Linux上可以使用TigerVNC的客户端;Windows上推荐使用UltraVNC (http://www.uvnc.com/ )
Whenever
I try starting the VNCserver service, it always failed.
Starting
VNC server: 2:myname [FAILED]
This "vncserver :1" from the user account solved the problem. It asked for Password, Created/Started whatever, and now VNC server starts well.
How to restart vncserver:
How difficult is to restart the VNC server or service? Well, there is certainly no difficulty at all, if you’re in front of the server.
Now, imagine that server is at few hundred miles away and nobody is there to restart that bloody machine.
Worst still, simply reboot the machine might not able restart the VNC server.
So, what could you do in order to get the VNC server back to work?
Precisely, if you can’t VNC to the remote server, how could you attempt
to restart the VNC service?
OK, here are the tips and tricks for VNC server running in Windows or Linux machine.
To apply this method, however, there must be network connection between you and the remote server.
Restart VNC service of a remote computer running Windows 2000 or above
You must do the following steps on a computer running Windows 2000
or above as well. Let say this is a Windows Vista Ultimate machine.
1) Click the Vista Orb (Start button), right-click on Computer and select Manage option from the pop-up menu. This will open Computer Management window.
2) Right-click the Computer Management (Local), the top node on left pane, and select Connect to another computer….
Alternatively, click the Action menu to find the same option.
3) In the Select Computer dialog box, opt for Another Computer and type the computer name in the text box.
If you can’t remember the computer name, click Browse button follow by Advanced button and click Find Now to list all computers detected.
Now, hopefully this step will be succeed. Otherwise, it ends here :-(
Once you’ve connected the remote computer, click Services and applications node on the left pane of Computer Management window. From there, locate the VNC service on the right pane and restart it.
Restart VNC service of a remote computer running Red Hat Enterprise Linux
With Linux, this job is easier :-)
Other than network connection, you must able to remotely login the Linux server, be it the vulnerable telnet or secure SSH protocol.
After login to Linux command prompt (via telnet or SSH), just execute service vncserver restart, if the VNC server is configured to auto-start when Linux boots up / reboot.
If there is no auto-start setup, then do the manual ways as you’ve done:
1) If the VNC server process stills exists, and it was started with DISPLAY:1, then kill it will command vncserver -kill :1
2) Start it again by executing vncserver :1
Now, you can confirm the VNC server is up again by executing netstat command:
netstat -tulpan | grep vnc
If the VNC server is started for DISPLAY:1, the netstat result
should shows Xvnc listening to three different ports: 5801, 5901, and
6001.
@Anja, my bad. There should be a space between “kill” and “:1″.
Thank for highlighting and it has just been corrected.

浙公网安备 33010602011771号