vnc

本文档介绍了如何检查和安装VNC客户端和服务器,配置`/etc/sysconfig/vncservers`,创建并更改VNC密码,启动和停止VNC服务,以及解决常见问题。通过VNC,可以远程共享多个用户的桌面,端口号为5800+N和5900+N,其中N是display号。VNC日志和xstartup文件位于`~/.vnc/`目录下。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

VNC相关命令:vncconfig vncpasswd vncserver vncviewer

1.检查vnc客户端(tscleint/vncviewer)和服务器是否已经安装在你的系统中
# rpm -qa|grep vnc
vnc-4.1.2-14.el5_3.1
vnc-server-4.1.2-14.el5_3.1
如果没有安装vncviewer,那么运行:
# yum install vnc
客户端我们也可以使用tscleint。

2.配置vncserver
vim /etc/sysconfig/vncservers
增加:VNCSERVERS="1:root"

3.vncpasswd创建一个vnc的口令
注意这将同时在你的home目录下,创建一个隐藏的目录.vnc,其中有一个文件passwd保存着你的vnc口令.

4. #service vncserver start

5. # vncserver (第一次启动时,需要指定一个密码)
You will require a password to access your desktops.
Password:
Verify:
New 'lpi:1 (root)' desktop is lpi:1
Creating default startup script /root/.vnc/xstartup
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/lpi:1.log

可以以多个用户身份,启动多个VNC,共享多个用户的桌面:
# lsof -i:{5901,5904}
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
Xvnc 2373 root 4u IPv4 6975 TCP *:5901 (LISTEN)
Xvnc 4236 test 4u IPv4 16231 TCP *:5904 (LISTEN)

可以手工指定display#,例如:
# vncserver :99
New 'lpi.123.com:99 (root)' desktop is server01.123.com:99
Starting applications specified in /root/.vnc/xstartup
Log file is /root/.vnc/server01.123.com:99.log

6.停止 vncserver(vncserver -kill :display#):
# vncserver -kill :1
Killing Xvnc process ID 2373

7.设置自动运行:ntsysv

8.VNC给浏览器的端口是5800+N,给vncviewer的端口是5900+N,N是设置的display号
http://192.168.1.1:5801/
ultravnc:192.168.1.1:5901
# lsof -i:5801,5901
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
Xvnc 31742 root 4u IPv4 51969 TCP *:5901 (LISTEN)
Xvnc 31742 root 5u IPv4 51970 TCP *:5801 (LISTEN)

9.修改VNC密码
# vncpasswd /root/.vnc/passwd
Password:
Verify:

VNC日志文件位于:$HOME/.vnc下的log文件,此目录也包含了一个VNC的xstartup启动文件。

以GNOME方式显示,修改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" &
gnome-session &
# tsclient
出现错误:unable to connect to host: Connection refused (111)
一般是没有指定连接的display#,例如地址输入:192.168.1.1出错,192.168.1.1:1就正确了

启动vncserver服务时,出现no displays configured :此错误,请编辑vncservers文件
#vim /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
# <URL:http://www.uk.research.att.com/archive/vnc/sshvnc.html>.

# 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:root"
VNCSERVERARGS[2]="-geometry 800x600 -nolisten tcp -nohttpd -localhost"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值