Ubuntu 16.10安装Xfce桌面与VNC远程连接

在远程服务器上运行桌面

通常在远程Linux服务器上工作时,您可以使用ssh终端。 但是,有时您需要在服务器上运行GUI应用程序,并保持运行一段时间。

这个想法实现很简单。 在服务器上安装您选择的任何桌面环境。 在本教程中,我们将使用Xfce,因为它与Gnome和KDE相比更具小巧。

然后使用vnc服务器启动桌面环境,并创建一个X显示会话,我们将通过vnc客户端从本地台式机访问。

安装桌面环境和VNC服务器

Xfce是一款轻量级桌面,非常适合在远程服务器上使用。 首先安装xfce软件包和tightvnc服务器。 在进行实际安装之前,最好先更新包缓存。

sudo apt-get update
sudo apt-get install xfce4 xfce4-goodies tightvncserver

请注意,这将只安装包,而不是启动任何东西。 我们将在本指南后面自行启动具体设置的vncserver。

如果dpkg进程意外退出,则可能必须运行以下命令 -
#sudo dpkg --configure -a

为vnc创建一个新用户

接下来要做的是创建一个将在vnc会话期间使用的unix用户。 用户名可以是任何东西。 使用adduser命令。

扫描二维码关注公众号,回复: 1958819 查看本文章

# adduser mike
Adding user `mike' ...
Adding new group `mike' (1001) ...
Adding new user `mike' (1001) with group `mike' ...
Creating home directory `/home/mike' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for mike
Enter the new value, or press ENTER for the default
        Full Name []:
        Room Number []:
        Work Phone []:
        Home Phone []:
        Other []:
Is the information correct? [Y/n]
#

vncserver将使用此unix用户启动桌面环境。 这意味着,在远程桌面上工作时,您将成为此用户

为用户设置“vnc密码”

vnc服务器维护一个单独的密码,用于通过vnc客户端登录到vnc服务器。 该密码与unix用户密码不同。 它使用vncpasswd命令配置。

首先切换到上一步中创建的用户“mike”,并设置vnc服务器密码。

su - mike

接下来使用vncpasswd命令

$ vncpasswd
Using password file /home/mike/.vnc/passwd
VNC directory /home/mike/.vnc does not exist, creating.
Password:
Verify: 
Would you like to enter a view-only password (y/n)?
mike@bunty:~$

请注意,passwd文件不存在,并在此步骤中首次创建。

如果您以前已经运行vncserver命令,那么它将创建文件。 当您第一次运行vncserver时,它会创建一个默认启动脚本

$ vncserver

You will require a password to access your desktops.

Password:                                                                                                                                           
Password too short
enlightened@desktop:~$ vncserver

You will require a password to access your desktops.

Password:
Verify: 
Would you like to enter a view-only password (y/n)? n

New 'X' desktop is desktop:1

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

但是,我们不需要运行vncserver命令。 它将使用启动脚本自动启动。

创建xstartup脚本

下一个重要的文件是xstartup脚本。 它包含有关哪些X应用程序开始的说明。 桌面环境是我们必须开始的X应用程序。

如果文件已经存在,首先要备份该文件
mv ~/.vnc/xstartup ~/.vnc/xstartup.bak

现在用nano编辑它

vnc@server:~$ nano .vnc/xstartup

注 - 这是用户vnc的主目录,即/home/mike/.vnc/xstartup

在xstartup脚本中输入以下几行

#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &

startxfce4命令将启动xfce桌面。 保存文件并关闭它。

使xstartup文件可执行。 这是必要的,以便vncserver可以执行此文件。

$ chmod +x ~/.vnc/xstartup

创建vnc服务文件

下一步是创建vnc服务文件,以便我们可以使用service命令启动vnc服务器,而不必每次都运行vncserver命令。

确保在USER变量中输入正确的用户名。 这是vnc服务器将用于启动桌面会话的用户。

粘贴以下脚本

#!/bin/bash
PATH="$PATH:/usr/bin/"
export USER="mike"
DISPLAY="1"
DEPTH="16"
GEOMETRY="1024x768"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
. /lib/lsb/init-functions

case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
;;

stop)
log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
;;

restart)
$0 stop
$0 start
;;
esac
exit 0

保存文件并关闭它。 使其可执行

# chmod +x /etc/init.d/vncserver

开始服务

开始并测试我们的步骤。

首先重新加载systemctl,以便它可以使用vncserver启动脚本。
systemctl守护进程重新加载

现在启动vncserver。 它在端口5901上启动服务器
#service vncserver start

检查它的运行

检查vnc服务器的打开端口。 从vnc客户端连接时,需要正确的端口号

# netstat -nlp | grep vnc
tcp        0      0 0.0.0.0:5901            0.0.0.0:*              LISTEN      24574/Xtightvnc
tcp        0      0 0.0.0.0:6001            0.0.0.0:*              LISTEN      24574/Xtightvnc
unix  2      [ ACC ]    STREAM    LISTENING    5225386  24574/Xtightvnc    /tmp/.X11-unix/X1

Vnc server can also be started by calling the script directly.

也可以通过直接调用脚本来启动Vnc服务器。

停止vncserver

# service vncserver stop

在桌面上安装vncviewer客户端

现在,我们将vnc服务器启动并运行GUI桌面环境。

在Ubuntu上安装xtightvncviewer。

$ sudo apt-get install xtightvncviewer

现在使用vncviewer命令连接到远程vnc服务器。

$ vncviewer -quality 5 -encodings“copyrect tight hextile zlib corre rre raw”-compresslevel 5 IPADDR:5901

我们使用较低质量和压缩编码来压缩正在传输的图像数据并使其更快。

使用像KRDC这样的其他vnc查看器可能会更慢。

猜你喜欢

转载自www.linuxidc.com/Linux/2017-07/145552.htm