ubuntu14.04上安装vncserver

时间:2021-07-18 06:31:16

vnc4server包:http://packages.ubuntu.com/trusty/x11/vnc4server

从这个网页中可以看到vnc4server包只支持i386和amd64硬件架构,如果ubuntu是安装在power架构的机器上,请使用x11vnc

vnc4server

1 登录服务器或ssh到服务器, 在ubuntu上安装vncserver: sudo apt-get install vnc4server xinetd

<pre name="code" class="plain">localadmin@ubuntu:~$ sudo apt-get install vnc4server xinetd
[sudo] password for localadmin:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
  xbase-clients
Suggested packages:
  vnc-java
The following NEW packages will be installed:
  vnc4server xbase-clients
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,579 kB of archives.
After this operation, 5,418 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://cn.archive.ubuntu.com/ubuntu/ trusty-updates/universe xbase-clients all 1:7.7+1ubuntu8.1 [2,756 B]
Get:2 http://cn.archive.ubuntu.com/ubuntu/ trusty-updates/universe vnc4server amd64 4.1.1+xorg4.3.0-37ubuntu5.0.1 [1,577 kB]
Fetched 1,579 kB in 14s (111 kB/s)
Selecting previously unselected package xbase-clients.
(Reading database ... 151666 files and directories currently installed.)
Preparing to unpack .../xbase-clients_1%3a7.7+1ubuntu8.1_all.deb ...
Unpacking xbase-clients (1:7.7+1ubuntu8.1) ...
Selecting previously unselected package vnc4server.
Preparing to unpack .../vnc4server_4.1.1+xorg4.3.0-37ubuntu5.0.1_amd64.deb ...
Unpacking vnc4server (4.1.1+xorg4.3.0-37ubuntu5.0.1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up xbase-clients (1:7.7+1ubuntu8.1) ...
Setting up vnc4server (4.1.1+xorg4.3.0-37ubuntu5.0.1) ...
update-alternatives: using /usr/bin/vnc4server to provide /usr/bin/vncserver (vncserver) in auto mode
update-alternatives: using /usr/bin/Xvnc4 to provide /usr/bin/Xvnc (Xvnc) in auto mode
update-alternatives: using /usr/bin/x0vnc4server to provide /usr/bin/x0vncserver (x0vncserver) in auto mode
update-alternatives: using /usr/bin/vnc4passwd to provide /usr/bin/vncpasswd (vncpasswd) in auto mode
update-alternatives: using /usr/bin/vnc4config to provide /usr/bin/vncconfig (vncconfig) in auto mode
 

2 开启vnc服务: vncserver

localadmin@ubuntu:~$ vncserver

You will require a password to access your desktops.

Password:
Verify:
xauth:  file /home/localadmin/.Xauthority does not exist

New 'ubuntu:1 (localadmin)' desktop is ubuntu:1

Creating default startup script /home/localadmin/.vnc/xstartup
Starting applications specified in /home/localadmin/.vnc/xstartup
Log file is /home/localadmin/.vnc/ubuntu:1.log

New 'ubuntu:1 (localadmin)' desktop isubuntu:1 表示vnc启动成功,并在主目录下生成.nvc目录。

注意:":1"代表display号,客户登录的时候得写相同的display号才能登录,:1表示5901端口。

3 在客户端下载“vnc viewer”软件,在服务器栏输入"ip:1"进行链接,输入用户名密码信息后,可以看到vnc连接页面,这是vncserver默认使用的窗口管理器是twm

4 修改vnc的默认设置,使启动时运行gnome桌面

修改vnc启动文件:vi ~/.vnc/xstartup

localadmin@ubuntu:~$ ls .vnc/
passwd  ubuntu:1.log  ubuntu:1.pid  xstartup
localadmin@ubuntu:~$ cat .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 &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
x-window-manager &
localadmin@ubuntu:~$ vi .vnc/xstartup
localadmin@ubuntu:~$ cat .vnc/xstartup
#!/bin/sh

# Uncomment the following two lines for normal desktop:
# unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc

#unset SESSION_MANAGER
#unset DBUS_SESSION_BUS_ADDRESS
#startxfce4 &


[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
#startkde &

gnome-session &
#gnome-panel &
#gnome-settings-daemon &
#metacity &
#nautilus -n &
#gnome-terminal &
#/usr/bin/gsettings set org.gnome.desktop.wm.keybindings panel-main-menu "['<Alt>F1']"
#/usr/bin/gsettings set org.gnome.desktop.wm.keybindings maximize "['<Alt>KP_5']"
#/usr/bin/gsettings set org.gnome.desktop.wm.keybindings unmaximize "['<Alt>F5']"
#/usr/bin/gsettings set org.gnome.desktop.wm.keybindings show-desktop "['<Primary><Alt>d']"
#/usr/bin/gsettings set org.gnome.desktop.wm.keybindings switch-applications "['<Alt>Tab']"
#/usr/bin/gsettings set org.gnome.desktop.wm.keybindings switch-group "['<Alt>Above_Tab']"
#/usr/bin/gsettings set org.gnome.desktop.wm.keybindings switch-input-source "[]"
#/usr/bin/gsettings set org.gnome.desktop.wm.keybindings switch-input-source-backward "[]"
#/usr/bin/gsettings set org.gnome.settings-daemon.plugins.media-keys terminal "['<Ctrl><Alt>t']"
#export DESKTOP_SESSION=ubuntu
#export GDMSESSION=ubuntu
#export STARTUP="/usr/bin/gnome-session --session=ubuntu"
#$STARTUP &

startkde & 启动KDE桌面

gnome-session & 启动gnome桌面

如果启动Unity桌面,首先去 /usr/share/gnome-session/sessions/下看桌面session的名称,如果是ubuntu-classic,则将最后一行改为:

export DESKTOP_SESSION=gnome-classic
export DGMSESSION=gnome-classic
export STARTUP="/usr/bin/gnome-session --session=ubuntu-classic"
$STARTUP

startxfce4 &:

        1. sudo add-apt-repository ppa:xubuntu-dev/xfce-4.12

zhai@zhai-VirtualBox:~$ sudo add-apt-repository ppa:xubuntu-dev/xfce-4.12
[sudo] password for zhai: 
 As always, install packages from PPA's at your own risk.

Xfce 4.12 packages for currently supported versions of Xubuntu. Please note that these are pre-release versions, which may contain annoying bugs and/or crash.

NOTE: For 12.04, you MUST enable the PPA for Xfce 4.10 packages (https://launchpad.net/~xubuntu-dev/+archive/xfce-4.10) as well.

If you need and/or want stable versions, wait for the final release date of Xfce 4.12. More information at http://wiki.xfce.org/releng/4.12/roadmap.
 More info: https://launchpad.net/~xubuntu-dev/+archive/ubuntu/xfce-4.12
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpnrfxkory/secring.gpg' created
gpg: keyring `/tmp/tmpnrfxkory/pubring.gpg' created
gpg: requesting key 142986CE from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpnrfxkory/trustdb.gpg: trustdb created
gpg: key 142986CE: public key "Launchpad PPA for Xubuntu Developers" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK
        2 sudo apt-get update && sudo apt-get dist-upgrade

        3 sudo apt-get install xfce4

$ sudo add-apt-repository ppa:xubuntu-dev/xfce-4.12
$ sudo apt-get update
$ sudo apt-get dist-upgrade

5 杀掉原桌面进程:vncserver -kill :1,再次生成新的会话: vncserver :1

localadmin@ubuntu:~$ vncserver -kill :1
Killing Xvnc4 process ID 2396
localadmin@ubuntu:~$ vncserver :1

New 'ubuntu:1 (localadmin)' desktop is ubuntu:1

Starting applications specified in /home/localadmin/.vnc/xstartup
Log file is /home/localadmin/.vnc/ubuntu:1.log

此时登录还是twm默认桌面

6 安装gnome桌面环境

自带桌面unity对VNC支持较差,需要在服务器上安装的gnome 3桌面

(1)安装xwindows的基础:sudo apt-get install x-window-system-core
(2)安装登录管理器:sudo apt-get install gdm (或kdm/xdm)
(3)安装ubuntu桌面:sudo apt-get install ubuntu-desktop(或Kubunut-desktop/ Xubuntu-desktop )

apt-get install gnome-desktop-environment

apt-get install metacity
另外:apt-get install gnome-core可以安装GNOME基础。

7 杀掉原桌面进程:vncserver -kill :1,再次生成新的会话: vncserver :1


x11vnc

VNC有很多选择,VNC4server,tigervncserver等等,都不推荐,难装又难用。经过多次实验和测试,最后只采用 x11vnc  作为VNC服务器端。


具体配置步骤如下:


# 步骤 1 - 安装 X11VNC  
sudo apt install x11vnc -y


# 步骤 2 - 配置访问密码
sudo x11vnc -storepasswd /etc/x11vnc.pass 


root@ubuntu:~# x11vnc -storepasswd /etc/x11vnc.pass
Enter VNC password: 
Verify password:    
Write password to /etc/x11vnc.pass?  [y]/n y
Password written to: /etc/x11vnc.pass

# 步骤 3 - 创建服务
vi  /lib/systemd/system/x11vnc.service

#粘贴如下代码,最后 :wq 保存,请使用root用户,否则没有权限。
[Unit]
Description=Start x11vnc at startup.
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /etc/x11vnc.pass -rfbport 5900 -shared
[Install]
WantedBy=multi-user.target

参数:
--localhost 在本地地址监听

-autoport PORTPORT开始选择可用端口监听

-rfbport PORT 指定监听端口

# 步骤 4 - 配置防火墙,配置和启动服务
sudo ufw allow 5900
sudo systemctl enable x11vnc.service
sudo systemctl daemon-reload

sudo systemctl start x11vnc.service


用vnc-viewer连接即可。


VNC实现Windows远程访问Ubuntu 16.04(无需安装第三方桌面)

https://www.cnblogs.com/xuliangxing/p/7642650.html

本文主要是讲解如果理由VNC实现Windows远程访问Ubuntu 16.04,其实网上有很多类似教程,但是很多需要安装第三方桌面(xfce桌面等等),而且很多人不太喜欢安装第三方桌面,很多人像笔者一样喜欢原生自带的桌面(O(∩_∩)O哈哈~有点强迫症)。今天笔者给大家介绍一下,不需要安装其他桌面,使用Ubuntu 16.04原生自带桌面如何进行远程访问。

一、设置Ubuntu 16.04 允许进行远程控制

   首先,我们先设置Ubuntu的远程控制,将其设置为允许被远程连接,进入系统-》首选项-》桌面共享,或者直接搜索桌面共享,如图所示

ubuntu14.04上安装vncserver

  将【允许其他人查看您的桌面】这一项勾上,然后在安全那项,勾选【要求远程用户输入此密码】,并设置远程密码。并且我们取消勾选【必须为对本机器的每次访问进行确定】(这样做,是为了被远程的时候不需要再确认,否则每次远程都要人为确认才能被远程,会很繁琐)如图所示:

ubuntu14.04上安装vncserver

二、安装vncserver

   其次,打开终端,我们需要安装vncserver的基础服务,输入以下命令:

sudo apt-get install xrdp vnc4server xbase-clients

  如图所示:

ubuntu14.04上安装vncserver

三、安装dconf-editor(取消权限限制)

   再次,我们需要取消掉请求加密的功能,否则缺少这一步是无法远程上的,这个时候我们需要安装dconf-editor工具进行配置,输入以下命令:

sudo apt-get install dconf-editor

  如图所示:

ubuntu14.04上安装vncserver

  安装完成之后,我们需要打开dconf-editor工具,在桌面搜索dconf-editor打开,如图所示:

ubuntu14.04上安装vncserver

  打开之后,依次展开org->gnome->desktop->remote-access,然后取消 “requlre-encryption”的勾选即可。如图所示:

ubuntu14.04上安装vncserver

  至此,前期准备工作已经完成,后面直接通过VNC工具或者Windows自带的mstsc(远程桌面控制)进行访问就行。

四、远程连接Ubuntu 16.04

  获取当前的IP地址,命令ifconfig即可得到,笔者的当前的Ubuntu的IP地址为:192.168.8.203,然后通过IP地址就可以远程访问了。

  方法一、通过VNC Viewer客户端进行访问

  大家可以到VNC官网(https://www.realvnc.com/en/connect/download/viewer/)下载最新的版本,根据自己实际情况,选择相对应的版本,如图所示:

ubuntu14.04上安装vncserver

  输入我们需要远程控制的PC主机的IP,如图所示:

ubuntu14.04上安装vncserver

  成功连接上了,如图所示:

ubuntu14.04上安装vncserver

 


  方法二、通过Windows自带远程桌面控制(mstsc)进行访问(个人推荐)

   个人比较推荐使用该方法,直接使用Windows自带的远程桌面控制工具进行远程访问,这样就可以不用VNC Viewer。直接打开自带远程桌面控制,输入目标PC的IP地址,如图所示:

ubuntu14.04上安装vncserver

  通过自带远程桌面控制工具,选择模式【vnc-any】,然后输入IP地址和密码进行登录(其中端口号默认为5900,保持不变就行)如图所示:

ubuntu14.04上安装vncserver

  成功连接了,如图所示:



参考:

http://help.aliyun.com/knowledge_detail.htm?knowledgeId=5974461

http://blog.chinaunix.net/uid-12084847-id-3508474.html

http://blog.chinaunix.net/uid-20528014-id-4714397.html

http://www.educity.cn/help/520296.html


https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-vnc-on-ubuntu-14-04

http://www.tuicool.com/articles/qm2MJnN

http://www.tuicool.com/articles/fiy2Aj

http://www.namhuy.net/3106/install-vnc-server-ubuntu-14-04.html