阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux 开启VNC远程管理服务的图形界面操作(解决灰色画面问题)

195次阅读
没有评论

共计 7004 个字符,预计需要花费 18 分钟才能阅读完成。

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 80×24+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 800×600″

这两行问题一般都可以解决。

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 800×600″

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 80×24+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 800×600″
VNCSERVERS=”1:root”
VNCSERVERARGS[1]=”-geometry 800×600 -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 80×24+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 1280×800 -alwaysshared -depth 24″
VNCSERVERS=”2:ocmsuser”
VNCSERVERARGS[2]=”-geometry 1280×800 -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 80×24+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 80×24+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~]#

CentOS 6.5 安装 VNC Server 实现图形化访问  http://www.linuxidc.com/Linux/2015-12/126262.htm

VNC 的安装配置 http://www.linuxidc.com/Linux/2013-05/84941.htm

CentOS 6.3 安装和配置 VNC http://www.linuxidc.com/Linux/2013-05/84668.htm

Linux 下强制不检测依赖安装 VNC http://www.linuxidc.com/Linux/2013-05/84075.htm

CentOS6 VNC 服务安装配置 http://www.linuxidc.com/Linux/2013-04/82510.htm

CentOS 下 VNC 配置和安装  http://www.linuxidc.com/Linux/2013-05/83975.htm

VNC 远程控制安装和设置 http://www.linuxidc.com/Linux/2013-01/77769.htm

Windows 通过 VNC 访问 Ubuntu  http://www.linuxidc.com/Linux/2012-10/73043.htm

Windows 远程桌面访问 Ubuntu 12.04 之安装 VNC http://www.linuxidc.com/Linux/2012-07/64801.htm

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-05/131319.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计7004字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中