Linux 开启VNC远程管理服务的图形界面操作(解决灰色画面问题)
Linux下VNC配置详解,以下配置为配置VNC详细介绍。并解决了用VNC View登入发现画面是灰色的问题
1. Linux下VNC的配置
首先在Linux的add/remove applications中的system tools下面安装VNC-server服务安装完成后直接输入vncserver 会出现以下内容:
passwd: //只有这个帐号是第一次运行vncserver,才会要求你输入连接的密码。
verify:
New 'server1.linux:4 (demo)' desktop is server1.linux:1
Starting applications specified in /home/.vnc/xstartup
Log file is /home/.vnc/server1.linux:1.log
上面这段话表示起动了一个图形终端,编号为1,要记住这个编号,等下登录时需要提供这个编号。第一次启动VNC一定要先直接输入vncserver。如果你要停止这个进程,使用命令
vncserver -kill :1
启动后就可以在客户端上面输入IP加刚才提到的那个编号即可登陆机器(xxx.xxx.xxx.xxx:1) 看到一个灰色的Xwindow桌面但上面什么也没有
运行过一次VNSERVER后会在HOME目录下面生成一个.VNC文件夹(在开始启动的时候可看到该文件夹的位置)注:该目录为隐藏,可直接输入路径进入。修改xstartup文件,去掉unset SESSION_MANAGER 和exec /etc/X11/xinit/xinitrc 前面的注释符号,将最后一行twm & 改成 gnome-session &
vi /root/.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 &
重新启动VNCSERVER即可
2、VNC的启动/停止/重启
#service vncserver start/stop/restart
关闭具体的vncserver命令:
vncserver -kill :1
vncserver -kill :2
3、设置密码
#vncpasswd
4、客户端登陆
在vnc客户端中输入:服务器端IP:1或服务器端IP:2
5、设置登陆到KDE桌面
注:很多情况下,提示VNC无法连接,或者提示10086错误都是没有修改vncservers文件的问题,所以编辑该文件修改
# VNCSERVERS="1:myusername"
# VNCSERVERARGS[1]="-geometry 800x600"
这两行问题一般都可以解决。
a.
[root@CentOS ~]# vi /etc/sysconfig/vncservers
# # 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:root"
# VNCSERVERARGS[1]="-geometry 800x600"
VNCSERVERARGS[1]=”-geometry 800×600 -alwaysshared -depth 24″
-alwaysshared代表允许多用户同时登录 -depth代为色深,参数有8,16,24,32。
注:红色部分就是被修改或增加的部分
b.
[root@centos .vnc]$ vi /root/.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" & #gnome-session & #set starting GNOME desktop startkde &#kde desktop
#twm &
#Text interface
注:红色部分就是被修改或增加的部分
c.
重启VNC即可。
vnc安装 Oracle:
出现错误提示:“Xlib: connection to ":1.0" refused by server”
如下处理:
实用技巧:在Linux下设置xhost方法步骤
source:http://www.knowsky.com/397544.html
第一步:用root登陆linux,启动vnc服务;
第二步:根据vnc起来的端口,设置export DISPLAY=localhost:1(1表示vnc在第一个tty上启动的),vnc的启动信息见附件1;
第三步:执行xhost +,并且提示“access control disabled, clients can connect from any host”才正确。
Linux下的操作日志如下:
[root@localhost ~]# vncserverNew 'localhost:1 (root)' desktop is localhost:1Starting applications specified in /root/.vnc/xstartupLog file is /root/.vnc/localhost:1.log[root@localhost ~]# export DISPLAY=localhost:1 [root@localhost ~]# xhost +access control disabled, clients can connect from any host
在设置xhost时,出现了unable的问题。
使用上诉方法就可以搞定。
一下为我以root身份登录的配置文件
[root@PC-223-CE ~]# 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
# <URL:http://www.uk.research.att.com/vnc/sshvnc.html>.
# VNCSERVERS="2:myusername"
# VNCSERVERARGS[2]="-geometry 800x600"
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 800x600 -alwaysshared -depth 24"
~
[root@PC-223-CE ~]# vi /root/.vnc/xstartup
#!/bin/sh
# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
xrdb $HOME/.Xresources
# [ -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 &
~
更改完后保存,重新启动VNC即可
3.多个用户登录
linux的VNC可以实现多个用户同时链接.方法如下
su 用户名
vncserver (这里就是第二个用户了)
第三个用户是
su 用户名
vncserver
添加完后需要在/etc/sysconfig/vncserver里面添加这个用户,不然就会出现登录后都是灰色的
另外还需要 修改用户目录下的.vnc/xstartup文件
例:我的电脑上已经有一个root用户,此时我还需要ocmSUSEr这个用户可以VNC登录
[root@linuxidc~]# su ocmsuser
[ocmsuser@linuxidcroot]$ vncserver
You will require a password to access your desktops.
Password:
Verify:
New 'ywei:2 (ocmsuser)' desktop is ywei:2
Creating default startup script /home/ocmsuser/.vnc/xstartup
Starting applications specified in /home/ocmsuser/.vnc/xstartup
Log file is /home/ocmsuser/.vnc/ywei:2.log
[ocmsuser@linuxidcroot]$ su - root
Password:
[root@linuxidc~]# 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
# <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[1]="-geometry 1280x800 -alwaysshared -depth 24"
VNCSERVERS="2:ocmsuser"
VNCSERVERARGS[2]="-geometry 1280x800 -alwaysshared -depth 24"
~
[root@linuxidc~]# cat /root/.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 &
[root@linuxidc~]# cat /home/ocmsuser/.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 &
[root@linuxidc~]# cp /home/ocmsuser/.vnc/xstartup /home/ocmsuser/.vnc/xstartup.bak
[root@linuxidc~]# cp /root/.vnc/xstartup /home/ocmsuser/.vnc/xstartup
cp: overwrite `/home/ocmsuser/.vnc/xstartup'? yes
[root@linuxidc~]# service vncserver restart
Shutting down VNC server: 2:ocmsuser [ OK ]
Starting VNC server: 2:ocmsuser
New 'ywei:2 (ocmsuser)' desktop is ywei:2
Starting applications specified in /home/ocmsuser/.vnc/xstartup
Log file is /home/ocmsuser/.vnc/ywei:2.log
[ OK ]
[root@linuxidc~]#