查看linux vnc用户名,Linux-VNC简单介绍

Linux-VNC

一、VNC简单介绍:

VNC,全称为Virtual NetworkComputing,它是一个桌面共享系统。它的功能,类似于windows中 的远程桌面功能。VNC使用了 RFB(RemoteFrameBuffer,远程帧缓冲)协议来实现远程控制另外一台计算机。它把键盘、鼠标动作发送到远程计算机,并把远程计算机的屏 幕发回到本地。VNC技术与平台无关,VNC Viewer可以和VNCServer在不同的操作系统上。VNC几乎支持所有的操作系统,也支持Java,甚至可以通过支持Java的浏览器来访问 VNCServer。多个VNC客户端可以同时连接到一个VNC Server上。VNC最初由AT&T开发的,它的源代码是开源的。

二、VNC在centos上安装VNC和VNCserver:

查看是否安装了vnc以及VNCserver

[root@localhost ~]# rpm -q vnc vnc-server

vnc-4.1.2-14.el5_3.1

vnc-server-4.1.2-14.el5_3.1

如果没有安装,则安装他们

[root@localhost ~]# yum install vnc vnc-server     #ubuntu的话,就是执行apt-get install vnc vnc-server

1.需要在每个用户下启动vncserver,生成该用户远程桌面连接时的配置文件以及访问密码,方法就是切换到每个用户,执行 vncserver。

(注 释:在启动VNCserver时,你也可以为server指定一个display参数。你可以把display理解为一个桌面,每个用户都可以有自己的桌 面。VNC客户端在连接时,可以指定连接到哪个桌面上。在系统中,display号不能重复,也就是说,如果有用户已经建立了名为“:1”的 display,另外一个用户就不能再使用“:1”了,他可以使用“:2”。

指定display号码的启动VNC server的命令是:   vncserver : 1

)

[root@localhost ~]# vncserver         #运行vncserver。

You will require a password to access your desktops.

enter password:                       #首次运行会让你设置密码,密码要求6位以上

verify password:                       #确认密码

xauth: creating new authority file /root/.Xauthority   #首次运行会生成本用户的相关配置文件,以及日志文件,生成位置在~.vnc/目录下

New 'CPAYNET005:1 (root)' desktop is CPAYNET005:1 注意这个数字1

Creating default startup script /root/.vnc/xstartup

Starting applications specified in /root/.vnc/xstartup

Log file is /root/.vnc/CPAYNET005:1.log     #注意这个数字

[root@localhost ~]# vncserver   -kill   :1    #杀死刚才运行的vncserver,数字1正是上面1.log那个1。注意上面红色字体。

[root@localhost ~]# vi ~/.vnc/xstartup       #编辑这个配置脚本文件,配置使远程登录为gnome或者kde桌面。

#!/bin/sh

# Uncomment the following two lines for normal desktop:

# unset SESSION_MANAGER

[ -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 &

#startkde kde若是用kde桌面,则将本行开始#号去掉,注释上面的gnome

[root@localhost ~]#su - otheruser     #切换到别的用户

[otheruser@localhost ~]$ vncserver #为用户名otheruser生成访问密码,以及远程连接时的配置文件

You will require a password to access your desktops.

enter passwd:

verify password:

xauth: creating new authority file /home/otheruser/.Xauthority  #首次运行会生成本用户的相关配置文件,以及日志文件,生成位置在~.vnc/目录下

New 'CPAYNET005:1 (otheruser)' desktop is CPAYNET005:1 注意这个数字1

Creating default startup script /home/otheruser/.vnc/xstartup

Starting applications specified in /home/otheruser/.vnc/xstartup

Log file is /root/.vnc/CPAYNET005:1.log     #注意这个数字

[root@localhost ~]# vncserver   -kill   :1    #杀死刚才运行的vncserver,数字1正是上面1.log那个1。注意上面红色字体。

[root@localhost ~]# vi ~/.vnc/xstartup       #编辑这个配置脚本文件,配置使远程登录为gnome或者kde桌面。原来vncserver默认使

#用的窗口管理器是twm,这是一个很简陋的窗口管理器,你可以把你的桌面改成GNOME或KDE。

#!/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 &

#startkde kde若是用kde桌面,则将本行开始#号去掉,注释上面的gnome

[otheruser@localhost ~]$exit            #切换回root

如果还有别的用户,重复执行上面紫色字体的步骤

2.接下来编辑vnc的配置文件

[root@localhost~]#vi /etc/sysconfig/vncservers

以下是文件内容:

# The VNCSERVERS variable is a list of display:user pairs.

# 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

# .

# 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:user1 2:user2 3:user3 “

VNCSERVERARGS [ 1 ] = “ -geometry 1024×768 “

VNCSERVERARGS [ 2 ] = “ -geometry 1024×768 “

VNCSERVERARGS [ 3 ] = “ -geometry 800×600 -depth 24 -nolisten tcp -nohttpd -localhost“

解释一下这个文件:

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,24色,不支持tcp,不支持http连接,只能在本地测试访问。

设置完成后就可以启动vncserver服务了。

[root@localhost~]#/sbin/service vncserver start

启动失败的原因有:

1./etc/sysconfig/vncservers文件参数不对

2.没有为vncservers提到的用户生成各自的配置文件

3.在生成配置文件后,没有使用命令vncserver -kill :1 将那个进程杀死

3. 最后,需要配置一下防火墙,允许VNC客户端连接VNC server。

VNC server监听的端口从5900开始,display:1的监听5901,display:2监听5902,以此类推。CentOs的防火墙缺省是不允许连接这些端口的,所以需要使用下面的步骤打开防火墙(需要root权限):

vi /etc/sysconfig/iptables

vi /etc/sysconfig/iptables 找到下面的语句:

-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited

在此行之前,加上下面的内容:

-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 5900:5903 -j ACCEPT

这句话的含义是,允许其它机器访问本机的5900到5903端口,这样,display:1, display:2, display:3的用户就可以连接到本机。

然后使用root身份重新启动防火墙:

[root@localhost~]#/sbin/service iptables restart

[root@localhost~]#/sbin/service iptables restart

好了,现在就可以运行客户端软件,连接到VNC server上了。

VNC客户端软件很多,在linux下有vncviewer,KDE还提供了一个krdc(它的菜单项就是”Remote Desktop Connection”,远程桌面连接)。

在window也有不少vnc客户端,你可以到http://www.realvnc.com/去下载一个,安装就可以用了。

假设VNC server的IP地址是192.168.1.1,display是:1。在VNC viewer的server栏中输入:“192.168.1.1:1”,然后连接。OK,你可以看到自己的桌面了。

a、在linux下,运行vncviewer命令即可,服务器地址的写法形如192.168.3.119:1

b、在windows下,运行windows版本的vncviewer即可,用法与linux下相近。

c、用浏览器(平台无关),作为java applet来实现,以形如http://192.168.3.119:5801的方式来启动   (vnc端口从5800开始依次类推,一般会是5800,5900)

4.设置vncserver为自动启动服务

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

有!我们可以把VNC server启动成后台服务。四种方法,我使用的是第三种方法C:

A方法:

执行如下步骤:

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

B方法:

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

cd    / etc / rc5 . d

cd / etc / rc5 . dmv K35vncserver S35vncserver

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

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

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

C方法:

[root@localhost ~]# chkconfig vncserver on

D方法:

把这行命令/etc/init.d/vncserver start加到/etc/rc.local启动项里。

附件:

一、查看vnc启动情况

[root@localhost ~]# 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

:5801            0.0.0.0:*                LISTEN    5248/Xvnc

tcp        0    0

0.0.0.0

:5901              0.0.0.0:*                LISTEN    5248/Xvnc

tcp        0    0

0.0.0.0:6001

0.0.0.0:*                LISTEN    5248/Xvnc

tcp        0    0 :::6001                   :::*                     LISTEN    5248/Xvnc

二、使用VNC View远程访问Linux,总是没有办法切换出SCIM输入法,研究了很久,终于让我找到了解决方法

1)修改.vnc/xstartup文件,在最后一行加入:scim -d,意思为打开SCIM输入法

2)使用VNC View访问Linux系统以后,修改scim输入法的快捷键,因为默认打开输入法的快捷键为ctrl+space,与本地机器上切换输入法的快捷键冲 突,系统会先接收到本地的命令,所以没办法使用默认快捷键打开输入法。将打开SCIM输入法的快捷键修改为Ctrl+Alt+Space。

作者“Thinking”

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值